Django Flow
In this lesson, you’ll walk through the flow of a request through a Django app. You’re going to see what happens when you type an address into your web browser and press Enter.
The first address point inside the Django app is the urls.py
in the management app. That file will direct you towards the urls.py
in the app you want to go to. That will forward you to views.py
, where the code logic happens. The functions in there will direct you towards a specific template to render and return to the user to see in the browser.
00:00 In this video, we’ll quickly talk over the flow of a request through a Django app.
00:08
Now, when you’re in your web browser and you type something in there, this is going to be the address of our localhost
app. Remember, here on the right, this is the file structure that we just looked at before.
00:20 Now, I want to show you what happens when you type in Enter here. How does the request flow through the Django app to finally present you the website? So, let’s say you click Enter here.
00:33
The next thing that happens is that the first address point for inside the Django app is going to be this urls.py
. The project-level management app urls.py
that’s defined inside of settings
—this is the first one to look at, and it directs us forward to the urls.py
inside of our app.
00:54
This one, again, forwards us to views.py
, where the code logic happens and the functions in here direct us to a specific template that’s going to get rendered and finally returned back to the user to see in the browser. All right, so, what happens if we change the URL up there?
01:14
Let’s say we want to see a specific project, so I’m typing 1
in here. And again, it goes through the same steps in the process. urls.py
, urls.py
, views.py
, into the templates/
, and then the template gets rendered and shown to us, the user on the front end.
01:33 There’s a little bit more to this whole process, and we’re going to dive deeper into it, but just so that you have kind of a connection between what’s happening in the browser and this file structure that we looked at before.
01:46 So, that’s all for a quick overview of the flow inside of a Django project. In the next video, we’re going to do a quick recap of what we talked about in this section of the course, and then we’re going to move on. So, see you in the next video!
Martin Breuss RP Team on Jan. 10, 2020
@lewiuberg - yes… kind of! :)
Django approaches the MVC topic a bit different than other frameworks, you can read this official answer to a related question.
The basic idea of MVC is to separate different topics (e.g. representation and code logic) into separate areas of your code. And you can see some of that in action when we’re looking at the different parts.
Here’s a nice article that talks some more about it. Hope this helps!
emalfiza on March 17, 2020
@Martin Breuss, a million thanks to this amazing explanation of Djano flow…
gregorysaison on Jan. 21, 2021
That’s maybe the best and important part of this Get Started With Django Part! Thanks for this very useful video Martin!
Become a Member to join the conversation.
lewiuberg on Jan. 9, 2020
Hi! Just wondering, is this the MVC pattern in action? Trying to connect the dots :)