Django Fundamentals: MVT, Models, the ORM, Admin and Migrations

Django fundamentals are the core ideas every Django project uses. Django follows a model, view, template (MVT) pattern: models define your data, views hold the logic for each request, and templates render HTML. URL patterns map web addresses to views.

May 16, 2025 - 10:33
Updated: 
101.8k

Python for AI & Automation in AI & Data · Course information

Django Fundamentals: MVT, Models, the ORM, Admin and Migrations

Quick answer: Django fundamentals are the core ideas every Django project uses. Django follows a model, view, template (MVT) pattern: models define your data, views hold the logic for each request, and templates render HTML. URL patterns map web addresses to views. The ORM lets you query the database with Python instead of raw SQL, migrations keep the database schema in step with your models, and the built-in admin gives you a ready-made interface to manage data. Learn these in that order with the official tutorial, using a supported Django release such as 5.2 LTS or 6.1.

Key takeaways

  • Django calls its pattern MVT: model, view, template.
  • A project holds settings; apps hold features.
  • The ORM turns Python queries into parameterised SQL.
  • Migrations record every change to your models.
  • The admin site is generated from your models with little code.

Table of Contents

What Is the MVT Pattern in Django?

The Django FAQ explains that what other frameworks call the controller is handled by the framework itself, so Django uses the terms model, view and template.

PartRoleLives in
ModelDefines data and database tablesmodels.py
ViewReceives a request, returns a responseviews.py
TemplatePresents data as HTMLtemplates folder
URLconfMaps URLs to viewsurls.py

What Is the Difference Between a Project and an App?

A project is the whole site: settings, root URLs and configuration. An app is a self-contained feature, such as a blog or polls, that can be reused. The official tutorial starts with these commands inside a virtual environment:

python -m pip install Django
django-admin startproject mysite
cd mysite
python manage.py startapp polls
python manage.py runserver

The runserver command is for local development only, never production.

How Do URLs, Views and Templates Work Together?

When a request arrives, Django checks the URL patterns in order, calls the matching view and passes it an HttpRequest. The view fetches data, often from models, and returns an HttpResponse, usually by rendering a template. Templates use variables, tags and filters, and they autoescape HTML by default, which protects against many cross-site scripting bugs.

What Are Models and the ORM?

A model is a Python class whose attributes become database columns. Field types such as CharField, IntegerField, DateTimeField and ForeignKey define the schema and relationships.

The ORM lets you make queries such as filtering, ordering and following relationships, all in Python. Querysets are lazy: nothing hits the database until you use the results. Because the ORM parameterises values, it helps prevent SQL injection, the main defence the OWASP SQL Injection Prevention Cheat Sheet recommends. Take care if you ever use raw SQL.

How Do Migrations Work?

Migrations are Django's way of applying model changes to the database schema. You change a model, generate a migration file, review it and apply it:

python manage.py makemigrations polls
python manage.py showmigrations
python manage.py migrate
CommandWhat it does
makemigrationsCreates migration files from model changes
showmigrationsLists migrations and whether they are applied
migrateApplies pending migrations to the database
sqlmigrateShows the SQL a migration will run

Commit migration files to Git so every environment builds the same schema.

What Does the Django Admin Give You?

The Django admin reads your models and builds pages to create, edit and delete records. Register a model in admin.py, create a superuser with python manage.py createsuperuser, and log in. It is designed for trusted staff, not as a public front end. In production, protect it with strong passwords and consider a non-default URL.

In What Order Should You Learn the Fundamentals?

  1. Python basics and virtual environments.
  2. Projects, apps and settings.
  3. URLs, views and templates.
  4. Models, the ORM and migrations.
  5. The admin site.
  6. Forms and authentication.
  7. Tests with the Django test runner.

Check the supported versions before you start; Django 5.2 is the LTS release with extended support until April 2028. Compare these ideas with Flask fundamentals to see what Django builds in. If you want an intensive format, read our Django bootcamp guide, or contact us about Django fundamentals training.

References

Frequently Asked Questions

Django uses the term MVT. The framework handles the controller role itself, so views hold request logic and templates handle presentation.

A project is the whole site with its settings and root URLs, while an app is a reusable feature package inside it.

The ORM parameterises query values, which prevents most SQL injection. Raw SQL or string formatting can reintroduce the risk.

It compares your models with existing migration files and writes new migration files describing the changes, ready for migrate to apply.

Yes. Migration files are part of your code, so every developer and server can build the same database schema from them.

No. The admin is meant for trusted staff to manage data. Build your own views for public users of the site.

No. The development server is not built for security or performance. Use a WSGI or ASGI server such as Gunicorn instead.

Install a supported release from the official download page. Django 5.2 LTS and 6.1 are both supported at the time of writing.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.