What Django is and how it works
Django is a Python web framework for websites and APIs that work with a database. Out of the box it includes an ORM with migrations, URL patterns, templates, an admin site and authentication: the data is described once with model classes, and the database tables and the admin site are built from them.
Django is a good fit when database content needs to be displayed, edited and administered: catalogues, customer dashboards, internal systems, APIs for mobile clients. The parts of the framework are loosely coupled: you can use a different template engine or work without the ORM, although Django templates work best with its own models. If all you need is a JSON API, where the OpenAPI documentation and input validation are built from type annotations and no admin site is needed, consider FastAPI.
Every request follows the same path. The web server passes it to Django, and the middleware processes it in the order of the MIDDLEWARE list. The URLconf then picks a view, which assembles the response from model data and a template. On the way back, the response passes through the same middleware in reverse order.
- The middleware listed in
MIDDLEWAREprocesses the request from top to bottom. Any of them can return a response straight away — the request then never reaches the view. - Django loads the root URLconf from the
ROOT_URLCONFsetting and tries the URL patterns inurlpatternsin order until the first one matches the request path. - Django calls the view of that URL pattern and passes it the
HttpRequestand the values captured from the path, such asyear=2026. - The view reads data through the models, renders a template and returns an
HttpResponse, or raises an exception such asHttp404. - If no URL pattern matched or an exception occurred, Django calls an error view — the 404, 500 and similar pages.
- The response passes through the middleware from bottom to top and goes to the web server.
from django.urls import path from . import views urlpatterns = [ path("year/<int:year>/", views.books_by_year),]from django.shortcuts import render from .models import Book def books_by_year(request, year): books = Book.objects.filter(published__year=year) context = {"year": year, "books": books} return render(request, "catalog/books_by_year.html", context)Model, template, view (MTV)
In Django terms, the model describes the data, the template — how to display it, and the view — which data to show at that address. The role of the MVC “controller” is played by the framework itself: it directs the request to the right view via the URLconf. That is why Django is called an MTV framework: model, template, view.
How it differs from FastAPI
| Aspect | Django | FastAPI |
|---|---|---|
| Purpose | websites with HTML pages built on its own templates, and APIs backed by a database | APIs built on Python type annotations |
| Database | its own ORM and migrations | no ORM of its own; the database is connected through a third-party library |
| Admin site | generated from the models; admin.site.register() is enough | none |
| API schema | does not build an OpenAPI schema; APIs are usually built with Django REST framework | OpenAPI schema, Swagger UI and ReDoc generated automatically; data is validated by Pydantic models |
Choose Django if the project has its own database, needs an admin site and pages for people, and the API is only one of its parts. Choose FastAPI for a standalone API service, where the API schema and type-based request validation matter more than models and an admin site.
What you need to know first
- Python: functions, classes, modules, virtual environments — the Python reference.
- HTTP: methods, response codes, headers — the HTTP and REST reference.
- SQL basics: tables, keys,
SELECTandJOIN— the SQL reference.
Section sources
the section is written from these pages- Django at a glancedocs.djangoproject.com/en/6.1/intro/overview/(opens in a new tab)
- URL dispatcher: How Django processes a requestdocs.djangoproject.com/en/6.1/topics/http/urls/(opens in a new tab)
- Middlewaredocs.djangoproject.com/en/6.1/topics/http/middleware/(opens in a new tab)
- FAQ: Generaldocs.djangoproject.com/en/6.1/faq/general/(opens in a new tab)
- Features - FastAPIfastapi.tiangolo.com/features/(opens in a new tab)