Django MVT Architecture

Is Django MVT or MVC?

  • Model: The Model represents the database. It is defined using Django’s built-in Object-Relational Mapping (ORM) system which allows developers to interact with the database using Python classes and objects instead of SQL queries. Models are thus connected to databases and interact with them defining the structure of the data.
  • View: Views are Python functions that handle HTTP requests and return HTTP responses. The View handles the user interface logic and controls the flow of data between the Model and the Template. The Views can access the Model layer to retrieve and manipulate data, and they can render that data on to templates for generating HTML responses.
  • Template: The Template defines how the data is presented to the user. It uses the data provided by the View to generate HTML pages, which are then sent to the user.

Overall, Django’s MVT structure provides a clear separation of concerns and helps developers to write modular, reusable, and maintainable code.

Let’s take an example :

Let’s take a example of dummyfacebook.com . Suppose a user puts in a request for dummyfacebook.com?page=codingaunty.

The logic of how things function(known as business logic) is provided by the View layer. The view decides what data needs to be sent to the user, fetches the data from the model and then renders the data in the corresponding template. In this case the view would ask the model to query the database for the data corresponding to codingaunty. This data would be sent back to the View.

The view would then send this data to the template and the template would present the data in form of an HTML page. This HTML page would now be sent back to the User in form of an HTML response.

Related Articles

Leave a Comment

Your email address will not be published. Required fields are marked *