Architecture used by Django — MTV

Stuti Kandpal
funccFORCE
Published in
3 min readApr 12, 2021

Are you thinking of developing (or developing) a project using Django?

If yes, then I assume you will put this in your resume as well!!

This article answers a very important question related to Django. The question is, “ Which Architecture Django uses? “

Now before moving to the architecture it uses, let me brief you with “what is Django?”

Django is an Open Source Web Framework that uses high-level Python. It allows the developers to focus on their apps instead of utilizing much time in the development of clean basic code. It takes care of most of the hassle of Web Development. It is fast, secure and scalable. And all this is for free!!

Hence, to develop a cool application, why not use Django and concentrate all our energy and time in the functioning of our apps and let Django handle the basic concept application of Web Development!!

Now, having discussed in short, “What id Django?” and “Why Django?”, let us move on to the next and very important question to be known by a Django User, “The Architecture”.

Architecture Used by Django

Django uses MTV architecture, i.e Models, Templates and View architecture. As we start an app in Django, we see few files/folders have been generated by default.

It also includes the following:

1. models.py

2. templates (folder)

3. views.py

These form up the basic components of MTV.

Let us discuss these components of MTV Architecture in little detail.

MTV Architecture Components

Model: It is the Logical Data Structure. It acts as the intermediator between the Database and View. It manages how and in what format, the database is fetched and written and modified.

Do you want to see where in your project you have it? Yes? Then, check models.py file which exists by default in your Django apps. Note that all the relations of the database are defined in this file with their attributes and their types after importing models from django.db using the following command:

from django.db import models

This function has been well defined by the Django developers and we do not need to care about taking care and writing code to manage the database as well, hence very efficient, time-saving and gives us more resources like time to experiment with how to apply these features to the best utilization.

The tables are defined in form of classes and hence utilizes object oriented approach and makes the objects more secure.

Templates: Template is the presentation layer, i.e. it looks upon how our app looks to the user. It basically, keeps everything that the browser may render.

The data can be presented best using templates and makes the app more interactive. It manages the client-side view of our Django app. It mainly focuses on the frontend and makes it more extendable and hence makes the working easier for frontend developers.

You can see a template folder inside your app. This folder will contain all your HTML files. (CSS and JavaScript and Images and other static files are kept separately in static folder)

Views: It is the data formatting layer. When the request has been made to the server, it fetches the information from this file and render/redirect/etc. To the required file contained in templates. Not only this, it also interacts with the database and the fetches the data or write or update the data in database as per the requirements. Therefore, it acts as an interface between the template and the model.

So, knowing the details of the components of MTV Structure of Django, we have understood, how basically Django works, and let us summarize this at this point.

Summary

Django uses MTV Architecture. Templates interact with the user and contain all files that are to be rendered by the server. It takes input requests. These input requests are then sent to Views which process these requests and responds. It can read, write and modify the database as well which forms the Model. It then responds with the required data to the request form template. The Model contains data and responds to the request sent by View.

--

--