DEV Community

Cover image for What is the Architecture of Django?
Penumudi Varun
Penumudi Varun

Posted on

What is the Architecture of Django?

The first time I was asked this question was not when i was learning Django, but after I had learned it and applied for an internship. During the internship, I was asked this question. Unfortunately, I didn't know the answer at that time, but now I do.

Every Django project you create follows an architecture called MVT. The MVT here stands for Mode Template View. These three things are main parts of any Django project. Let's see about them in detail.

Django Architecture Diagram

Model

A model is a class based representation of a table in a database. Django applications use python classes to represent a table in the website database, these classes are called models in django. All the model classes you create in django should inherit from "django.db.models.Model" class. Each model class will have attributes that represents the fields of the database table.

View

The view is the function or class that contains necessary logic to take in a HTTP request coming from the client and send the appropriate HTML, json or some other response back to the user. In Django these views can be class based or function based in Django.

The view takes in the url path, query parameters along with request body sent by the user/client then uses this data to perform CRUD operations if needed, and sends back the responses.

Template

The template in Django is nothing but a HTML file that defines the layout and contains body of webpage along with some other script written in special templating syntax supported by Django.

Using this special templating syntax we can show the dynamic data on the website. This dynamic data is actually given by a Django view to the template and it usually contains the information about models of the Django project.

MVT and MVC?

The MVT architecture used by Django is a slightly different version of another popular architecture called MVC. Here MVC stands for Model View Controller. Here Model, View and Controller stands for

Model: The model here represents the data and business logic. The model handles the data and business logic of the application similar to the model in Django's MVT.
View: The view here is different. It doesn't contain the logic for handling http requests, instead it represents UI elements. So, the view in MVC is more similar to template in MVT
Controller: The Controller in this architecture is responsible for the logic for controlling the requests and user inputs. So controller here is more like view in the MVC

So, this is all you should know about the Django's architecture. If you have any questions feel free to ask them in comments.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Heroku

This site is powered by Heroku

Heroku was created by developers, for developers. Get started today and find out why Heroku has been the platform of choice for brands like DEV for over a decade.

Sign Up

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay