How Does Django Actually Work?

How Does Django Actually Work?

/ #Django

In this video, I will try to explain how Django works. I will talk a little bit about the different parts of Django like views, models, urls and similar.

I will also talk a little bit about how everything is connected, what happens when you go to a page and similar.

What is Django?

Django is a framework based on Python for building web sites and web applications. Django is insanely fast, takes security seriously and it's easy to scale. Python is very beginner friendly, and since Django is based on this, it makes Django easy to get started with as well.

Django Project vs Django Apps

It can be a little bit confusing in the beginning, because there are a lot of terms and words you might not have heard about before. Your whole web site is a Django project. And the Django project is a collection of apps.

For example my website is a Django project. And the project has multiple apps like blog, course and similar. A Django app usually consist of some models, templates and views. I will go into each of these a little bit more in detail.

What happens when you go to a page

Let's say you go to

First, the web server will get a request which will be "passed on" to Django.

Then the "" file will be triggered. Very little happens here, it just initialize the environment and select which settings file to use.

The settings file contains information on which urls file to use.

And in the file, things starts to happen. The url file contains a list of the pages like the front page, about, category, post detail and similar.

Django will now find the correct page based on information from the url.

"an-article-example/" will not match this:
path('about/', views.about, name='about')

But it will match on this:
path('/', views.post_detail, name='post_detail')

What happens here is that Django knows that we expect a dynamic address here called slug. When this matches, it will call a view called "post_detail".

So in a few words, the flow will be:

Browser -> Web server -> -> -> -> -> template.html -> the results

Interested in learning more Django? Check out my collection here: Django tutorials



No comments yet...

Add comment


Subscribe to my weekly newsletter. One time per week I will send you a short summary of the tutorials I have posted in the past week.