Django - MVT explained

MVC framework

The Model-View-Controller (MVC) is an architectural pattern that separates an application into three main logical components viz Model, View and Controller.

Each of this component is built to handle specific development aspect of an application.

MVC is popular in designing web and mobile applications.

View: 

A view is a part of an application that represents the presentation of data. A view requests the model to give information so that it presents the output to the user.

A view consist of any or all of UI components like text boxes, buttons, dropdowns, charts, diagrams, tables, etc.,

Controller:

The controller is a part of the application that handles the user interaction. The controller interprets the inputs from the user like mouse, keyboard, touch, etc., and informs the model and view to change as appropriate.

A controller sends commands to the model to update its state, and sends commands to its associated view to change the view's presentation.

Model:

The model component stores data and its related logic. A controller object will retrieve the customer info from database, manipulates the data and sends back to database or renders the data to view.


Django Model:

The purpose of the model in Django is same as the model in the MVC, it provides interface for storing and maintaining the data in the database.

RDBMS software such as MySQL, PostgreSQL are used by the model.

Model responds to the requests created by view.

Django View:

The view accepts the user input made by the Template mode, retrieves  the data from the database via the models, and sends back the response to the user.

It takes care of the interpretation of the user's request to instruct the Model for data retrieval and convert the data to present it in a user-friendly manner.

Django uses the idea of request-response by creating HTTP requests and response objects.

When a page is requested, Django creates an HTTP requests object. The view receives that request from the user and then accordingly processes the data in the database via the models. Then the view is held responsible for presenting the model to the user and an HTTP response object.

Django can do a lot more work than just handling requests and responses.

Django's middleware is a framework that handles all the requests and response processing, after following all the necessary security and authentication checks.

Templates:

The Template in Django works same as View in the MVC. It provides user interface to users.

Template handles all the HTML, CSS, and displays the actual content of the web applications the user is using. It takes all the user's input and provides easy interaction with the web applications.

Django users Django Template Language (DML) by which one template can be used by multiple views to represent different kinds of data.


USER => Django Framework => URL => Django View => Template

USER => Django Framework => URL => Django View => Model => Database


MVC vs MVT

MVC => controller handles both Model and View

MVT => View is responsible for all HTTP request and responses, the Django framework manages the controller part.

MVC is not suitable for small web applications due to its complexity.

MVT is best option for both small and large applications.



Comments

Popular Posts