Django Model View Template (MVT)

The Django framework is based on the Model-View-Template (MVT) architecture. MVT is a software design pattern for developing web applications. This web-framework software acts as a tool that provides a way to build and run web applications.

1. MVT Structure

    • Model: This is an abstraction layer for structuring and manipulating the data of the Web Application. It acts as an interface for maintaining data. This is a logical data structure behind the entire application and helps to handle the database.
    • View: This layer encapsulates the logic responsible for processing a user’s request and returns a response. It is a user interface to execute the logic and interact with the models. It is responsible for displaying all or a portion of data to the user.
    • Template: The template layer provides a designer-friendly syntax for rendering the information to be presented to the user. It contains the static parts of the desired HTML output along with some special syntax, also known as Django Template Language (DTL), describing how dynamic content will be inserted.

2. MVT vs MVC

Usually, web-application frameworks use the Model-View-Controller (MVC) architecture. MVC is popular as it isolates the application logic from the user interface layer and different parts of the application can be developed separately. Here, the controller part is the software code that controls the interaction between the model and the view.
As Django works on the concept of MVT, it itself takes care of the controller part and we do not have to worry much about how the data moves between the model and the view.

3. MVT Working

Django MVT Control Flow

The Model is the middleware handles data between the database and the view using the specified definitions for the data fields. The views receive the data as well as a request (‘POST’, ‘GET’, etc) from the client and then accordingly process the data in the database via the models. This data is available on the user interface with the help of the templates. Using the Django Template Language, one template can be used by multiple views to show different kinds of data. The templates (or the HTML pages) contain the data output response from the views and are then rendered by the browser at the specified url. This is visible on the client-side while the models and the views reside on the server-side.

  1. References

    1. Django Documentation
    2. MVC Architecture
    3. Django MVT
    4. Django Rendering Static HTML Pages

Happy Learning 🙂

About the Author:

Ketan
An aspiring software engineer, exploring the dimension of Computers and Tech.

Leave A Comment