100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Python

The MVT Architecture

How Django splits an application into Models, Views, and Templates, and how the framework itself acts as the controller that wires the three together on every request.

Django FoundationsBeginner9 min readJul 10, 2026
Analogies

The MVT Architecture

Django organizes application code using the Model-View-Template (MVT) pattern, a variant of the classic Model-View-Controller (MVC) pattern. In MVT, the Model defines the data structure and business rules (typically a Python class in models.py mapped to a database table), the Template defines how data is presented as HTML, and the View contains the logic that fetches data from the Model and passes it to the Template. The key difference from traditional MVC is that Django itself acts as the controller, using its URL dispatcher to route each incoming request to the correct view function automatically, so developers don't write a separate controller layer.

🏏

Cricket analogy: Similar to how a cricket match separates the scorer (Model, recording runs and wickets), the scoreboard display (Template, showing the score to the crowd), and the umpire's decision logic (View, deciding what to display next), Django's MVT splits data, presentation, and logic into three distinct roles.

Models: Defining Data

A Model in Django is a Python class that subclasses django.db.models.Model, where each class attribute becomes a database column via a field type such as CharField, IntegerField, or ForeignKey. Django's ORM translates this Python class into SQL automatically: calling Article.objects.filter(published=True) generates a SELECT query with a WHERE clause without the developer writing raw SQL, and running python manage.py makemigrations followed by migrate generates and applies the corresponding CREATE TABLE or ALTER TABLE statements.

🏏

Cricket analogy: Similar to how a scorecard defines fixed fields for every player — runs, balls faced, and dismissal type — that get filled in identically for every match, a Django Model defines fixed fields like title and published that get filled in identically for every row in the database.

Views and Templates: Logic and Presentation

A View is a Python function or class in views.py that receives an HttpRequest, fetches or manipulates data through the Model layer, and returns an HttpResponse, usually by rendering a Template. Templates live in .html files using Django's own template language, which supports variable interpolation like {{ article.title }} and control-flow tags like {% for article in articles %}, but deliberately restricts arbitrary Python execution inside templates to keep presentation logic simple and separate from business logic, which belongs in the view or the model.

🏏

Cricket analogy: Similar to how a match referee decides what data to relay to the broadcast (View) while the graphics team formats it for the scoreboard (Template), a Django view fetches article data and passes it to a template that renders {{ article.title }} for display.

python
# models.py
from django.db import models

class Article(models.Model):
    title = models.CharField(max_length=200)
    body = models.TextField()
    published = models.BooleanField(default=False)

# views.py
from django.shortcuts import render
from .models import Article

def article_list(request):
    articles = Article.objects.filter(published=True)
    return render(request, 'articles/list.html', {'articles': articles})

<!-- templates/articles/list.html -->
{% for article in articles %}
  <h2>{{ article.title }}</h2>
{% endfor %}

Business logic belongs in the model or view, not the template. Django's template language intentionally cannot run arbitrary Python, so pushing calculations into templates leads to convoluted, hard-to-test template tags.

  • MVT stands for Model-View-Template, Django's variant of the MVC pattern.
  • The Model defines data structure and lives in models.py.
  • The View contains logic that fetches data and returns an HttpResponse.
  • The Template renders HTML using Django's restricted template language.
  • Django itself acts as the controller via its URL dispatcher.
  • Templates deliberately cannot execute arbitrary Python for separation of concerns.
  • makemigrations and migrate keep the database schema in sync with Model changes.

Practice what you learned

Was this page helpful?

Topics covered

#Python#DjangoStudyNotes#WebDevelopment#TheMVTArchitecture#MVT#Architecture#Models#Defining#StudyNotes#SkillVeris