The MVC Model (Django's MTV)
Open any real Django project and the code is spread over files called models.py, views.py and a templates folder. That split is not an accident. It follows an old, reliable idea for keeping a web app understandable as it grows: keep the data, the decisions and the display apart.
The rule
Model holds data, view decides, template shows.
Classic MVC (model–view–controller) names three roles. Django keeps the idea but uses its own names, often called MTV:
| Role | Classic MVC | Django |
|---|---|---|
| The data and its rules | Model | Model (models.py) |
| Deciding what to do with a request | Controller | View (views.py), reached through urls.py |
| What the user sees | View | Template (.html files) |
The naming clash catches everyone once: in Django, a view is the decision-maker, not the display.
Here are all three for the cookbook's recipe list:
# models.py: the data
class Recipe(models.Model):
title = models.CharField(max_length=200)
minutes = models.PositiveIntegerField()
# views.py: the decision
def recipe_list(request):
quick = Recipe.objects.filter(minutes__lt=30)
return render(request, "recipes/list.html", {"recipes": quick}){# templates/recipes/list.html: the display #}
{% for recipe in recipes %}
<article class="card">{{ recipe.title }}, {{ recipe.minutes }} min</article>
{% endfor %}Django's own routing machinery, the part that receives the request and picks a view, does the rest of the controller's job.
The shortcut
For any piece of code, ask one question: is it about data, decisions, or display? Data → model. Decisions → view. Display → template.
Route
urls.pymatchesrecipes/and hands the request to therecipe_listview.
The trap is leaking roles: queries inside templates, or HTML strings built inside views. When the designer and the data change for different reasons, they should live in different files.
Drills
Answer fast — trust the rule.
In Django's naming, what plays the role classic MVC calls the "view"?
Where does title = models.CharField(max_length=200) belong?
A designer restyles the recipe cards. Which piece should they need to edit?
"If the visitor is not logged in, send them to the login page." Where does this go?
Remember
- Model holds data, view decides, template shows.
- Ask "data, decisions or display?" to place any piece of code.
- Trap: a Django "view" is the controller-like part, not the HTML.
