Flask: The MVC and MTV Architectures | WSGI and Jinja2 (Pt.2)

Flask: The MVC and MTV Architectures | WSGI and Jinja2 (Pt.2)

Hi!

In this article I'd be talking a bit about the Model-view-controller architecture (MVC), the Model-Template-View (MTV) architecture and the difference between both.

Model-View-Controller Architecture

The MVC architecture is a software architectural pattern where application logic is divided into three components based on functionality, namely:

  • Models
  • Views
  • Controllers

This architecture is used for desktop applications, mobile and web applications.

Components of MVC architecture

MVC architecture

  • Models:

    It contains all the data definitions for your application (the schema) and represents how data is stored in the database.

  • Views:

    These are the visible components that the user can interact with, such as a Graphic User Interface (GUI) or HTML pages.

  • Controllers:

    This component interprets the interactions and acts on the models before data is returned through views. It acts as an interface between models and views.

Model-template-view (MTV) architecture

MVT architecture

It's a little bit different from the MVC architecture. Since Flask is a microframework, it doesn't support an architectural framework buuut MTV got introduced because developers who use Django introduced it.

The difference between both of them is for MVC, we have to write control specific code but for MVT, the controller part is taken care of by the framework itself which sends a template as a response.

Web Server Gateway Interface (WSGI)

It is a standard that describes the specifications that concern communication between a client application and a web server. It's detailed in PEP333.

Some benefits of this are:

  • It allows the components of the application to be flexible.
  • It enables the application to be scalable when there's an increase in users.
  • It offers efficiency in terms of development and speed.

The Jinja Template

It is a template language used In Python. In a previous article, we talked about MVC and MTV which mentioned something about templates. Well, in this case of web development, a template is the HTML pages. We can use a template language in an HTML page so that the content becomes dynamic.

References: