In this article, we will talk about the Django MVT architecture and how is it different from the long-existing MVC architecture. So let’s get right into the topic and understand the Django MVT arhitecture.
But before that, we’ll briefly go over the MVC Architecture here.
What is MVC Architecture?
MVC architecture has been there for a long time in the software industry. All most all languages employ MVC with slight variation, but the concept remains the same.
MVC stands for Model – Views – Controller
- Model – A model provides the interface for the data stored in the Database. It is responsible for maintaining the data and handling the logical data structure for the entire web application.
- Views – A view in MVC is a user interface. It is responsible for displaying Model Data to the user and also to take up information from the user. Views in MVC is not the same as the Views in Django. We will learn the difference later in this article.
- Controller – A controller in MVC is responsible for the entire logic behind the web application. That is when the user uses a view and raises an Http request, the controller sees the user request and sends back the appropriate response.
Django prefers to use its own logic implementation in its web app and hence its framework handles all the controller parts by itself.
Hence Django implements a different kind of architecture called MVT (Model – View – Template) architecture.
What is the Django MVT architecture?
MVT architecture is the software design pattern used by the Django web framework.
MVT stands for Model – View – Template.
Just like the Model in MVC, here as well it has the same functionality of providing the interface for the data stored in the database.
Just like View in MVC, Django uses templates in its framework. Templates are responsible for the entire User Interface completely. It handles all the static parts of the webpage along with the HTML, which the users visiting the webpage will perceive.
In Django, Views act as a link between the Model data and the Templates.
Note: Just like the controller in MVC, views in Django MVT are responsible for handling all the business logic behind the web app. It acts as a bridge between Models and Templates
It sees the user request, retrieves appropriate data from the database, then renders back the template along with retrieved data.
Therefore there is no separate controller in Django MVT architecture and everything is based on Model -View – Template itself and hence the name MVT.
Control Flow of MVT
Here as shown in the above picture
- The user sends a URL request for a resource to Django.
- Django framework then searches for the URL resource.
- If the URL path links up to a View, then that particular View is called.
- The View will then interact with the Model and retrieve the appropriate data from the database.
- The View then renders back an appropriate template along with the retrieved data to the user.
That’s it, guys!! This was all about the Django MVT architecture. For more information about each of them, do check out the Django Models, Views, and Templates articles. Keep coding !!