Trending Articles       10 Flutter Listview Examples       Flutter Custom Button Example       Flutter Audio Recording       Flutter 2.0 Autocomplete TextField       Current Location Google Maps

Django Tutorial - MVT Pattern on Django (Model View Template)

In this Django tutorial series we will cover design pattern in Django. This design pattern is MVT design pattern. Let's discuss about MVT

The MVT (Model View Template) is a software design pattern. This MVT design pattern consist of three important components which are named as Model, View and Template. Similarly Django follows the MVC pattern but it maintains its own conventions. So, control is handled by the Django framework itself



Basically Model act as Meditator Between the Website Interface and the Database. In Django, We use Python Classes To make Models Which is nothing but a Table in a Database. Class Attributes is Columns of the Table in the database and on these attributes we can set constraints like primary key, foreign key, Many to Many Relation, one to many Relation, etc. So using Models in Django makes it easy to connect with the database. or we can say that model is the whole logic of your project or business


from django.db import models

# Create your models here.
class Author(models.Model):
    name = models.CharField(max_length=200)
    email = models.EmailField()



The View is used to execute the business logic and interact with a model to carry data and renders a template. The view can be a function-based view or can be Class-based view. when the user requests something there is basically a function or class is written to handle those requests. for example when the user request ‘’. so basically here user requested for the home page of your site and after this, the view you have written to handle this particular request will return the response to the user in the form of an HTML file or we can say that HTTP response

from django.shortcuts import render
from .models import Author

# create a function (view)
def author_view(request):
    return render(request, template_name, {"author":author})




In Django, Templates are nothing but the HTML file which handles the User Interface part completely. These Templates rendered when the user requests these templates. So basically templates are returned response by the view to the user requests


<!DOCTYPE html> 
<html lang="en"> 
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta http-equiv="X-UA-Compatible" content="ie=edge"> 
    <title>Author Page</title> 
    <h1>Welcome to {{ }} Page</h1> 
    <p> Email Id : {{ }}</p>


So let's look at this in Picture

Django MVT design pattern



Here you can see that user requests to your Django site. user has written some URL (Uniform Resource Locator) like after this, URL will match to the specified View, Now View will check the request object if there are any attributes related to Database it will fetch from or save those attributes to the database. If there are no Attributes related to the Database simply it will look for an HTML page (templates) to return a response but if it doesn’t found any templates it will show the error “404 pages nor found


#Django, #Design pattern, #MVT Design Pattern

Article Contributed By :


Flutter Questions

Android Questions