Django uses Model–View–Template (MVT), a variation of MVC. The framework itself acts as the controller—routing URLs to views and coordinating templates.
The three layers
- Model — Python classes mapping to database tables (
models.py); business data and validation rules - View — Python functions or classes handling a request; query models, return HTTP response
- Template — HTML with Django template language for dynamic output
Request flow (simplified)
- Browser requests
/articles/5/ urls.pymaps the path to a view function- View loads
Articlefrom the ORM, builds context dict - Template renders HTML; Django returns the response
myproject/
manage.py
myproject/
settings.py
urls.py
blog/
models.py
views.py
urls.py
templates/blog/detail.html
Important interview questions and answers
- Q: MVT vs MVC?
A: In MVC the controller handles routing; in Django the framework is the controller—your "view" is the controller logic plus response building. - Q: Where does business logic live?
A: Models (data rules), views (request handling), sometimes services/utils—avoid fat templates. - Q: What is an "app"?
A: A reusable module (blog, accounts) with its own models, views, and templates inside a project.
Self-check
- Which file maps URLs to view functions?
- What does a template produce?
Tip: Draw MVT on paper: URL → view → model query → template → HTML. The "controller" role is Django itself plus your view function.
Interview prep
- MVT vs MVC?
Django's "view" is your request handler; the framework itself routes URLs and coordinates templates—the controller role is split between Django and your view code.