DEV Community

almasi-y
almasi-y

Posted on

Django: Figuring out the MVT Architecture Versus the MVC

What exactly is an architecture in a framework

  • You might be wondering: why do we need an architecture in a framework.

  • Well, an architecture in a framework in layman's term it's the way the framework is layered or arranged, how it will be operating and interacting with its components for example view in this case has to be interacting with models and templates

The Model View and Template

  • Model – A model is an object that defines the structure of the data in that particular app it is in. It's responsible for maintaining the data and handling the logical data structure for the entire web application.

  • Views – A view is a function that handles the Http requests and responses. It will accept the requests, process them and return the Http responses.

  • Templates - Templates are files that define the structure of the entire User Interface completely. It handles the static components of the webpage, including the HTML that users encounter.

  • So now that we know what an architecture is and the definition of each component in a MVT architecture, it's much easier then to introduce the fact that the MVT is sort of a control flow.

-This control flow starts immediately when a user interacts with a Django web page as shown below:

Control Flow in MVC architecture

The Control Flow
Here are the steps that fall into place when a user interacts with a Django application:

  1. For a user to interact with the django app they have to use a url, so the user sends a url request

  2. Using a URL mapper, the request will be redirected to the appropriate view if it is there

  3. Once the view is found it is then called because again it is a function, remember

  4. The view now communicates with the model to retrieve or for the model to give the data requested by the url

  5. The view also communicates with the template and populates it with the data it has received from the models and sends it to the user interface

MVT VERSUS MVC

  • You have now gotten the jist of what MVT architecture is and how it essentially works, so now how is the conventional MVC(Model View Controller) different from this.
  1. Handling user input and updating model and views:- In MVC the controller is responsible for this role while in MVT the role is shared between handling of routes that is in-built in django and the views functions

  2. The view in MVC depends on the controller for data as it defines what the user sees while the view in MVT interacts directly with the model hence combining logic and user interface

MVT overtakes MVC when it comes to simplicity. Because MVT does not have a controller that separates the logic, routing and user interface, there is less boilerplate code hence simplifying development

References
https://www.educative.io/answers/what-is-mvt-structure-in-django
https://www.askpython.com/python-modules/django/django-mvt-architecture

Top comments (0)