Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

DJ
Django & FastAPI
0/12 completed
Beginner
How Python web frameworks workYour first FastAPI appRequest bodies and Pydantic models
Intermediate
FastAPI with a databaseDependencies, routers and testingDjango: projects, apps and the ORMDjango views, URLs and templatesForms, the admin and class-based views
Advanced
APIs with Django REST frameworkAuthentication in Django and FastAPIBackground tasks and async
Pro
Deploying Python web apps
Tracks / Django & FastAPI / Beginner

How Python web frameworks work

Python powers the backends of Instagram, Spotify, Dropbox, Reddit and countless startups. Its two most popular web frameworks take different approaches: Django, "the web framework for perfectionists with deadlines", ships everything included; FastAPI is a modern, fast framework focused on APIs with automatic validation and documentation. This track teaches both.

The editors in this track run real Python 3.14, FastAPI and Django in your browser. The first run of a lesson downloads the framework (a few MB, then cached). Instead of starting a server and opening a browser, each example sends requests to the app in code, the same way automated tests do.

What a web framework does

Every web app does the same basic job: receive an HTTP request, decide which code handles it (routing), run that code, and send back a response. A framework handles the repetitive parts:

Job Without a framework With one
Parse URLs, headers, query strings, bodies By hand request.query_params, request.json()
Routing if path == … chains @app.get("/items/{id}") or path("items/<int:id>/", …)
Validation Manual checks Type hints (FastAPI) or forms (Django)
Database Raw SQL An ORM (Django ORM, SQLAlchemy, SQLModel)
Security Easy to forget CSRF protection, password hashing, escaping built in

The interface underneath: WSGI and ASGI

Python web servers and frameworks agree on a standard interface, so any server can run any framework.

WSGI (Web Server Gateway Interface, 2003) is a function that receives the request as a dictionary and returns the body. Django and Flask are WSGI frameworks. Here's a complete WSGI app, called directly (no server needed):

Python · editable

ASGI (Asynchronous Server Gateway Interface) is the modern, async successor: an async function that receives and sends messages. It supports WebSockets and long-lived connections, and lets one process handle many requests while they wait on databases or other APIs. FastAPI and Starlette are ASGI frameworks; Django supports both.

Python · editable

You'll never write raw WSGI or ASGI in practice, but now you know what gunicorn myproject.wsgi and uvicorn main:app actually run.

Django, FastAPI or Flask?

Django FastAPI Flask
Style "Batteries included" API-first, type-hint driven Minimal, add what you need
Interface WSGI and ASGI ASGI WSGI
Database Built-in ORM + migrations Your choice (SQLModel, SQLAlchemy) Your choice
Admin panel ✔ automatic ✖ ✖
HTML pages ✔ templates, forms Possible (Jinja2) ✔ Jinja2
Validation Forms, serializers (DRF) Pydantic, from type hints Extensions
API docs With DRF + extensions ✔ automatic (OpenAPI, Swagger UI) Extensions
Best for Full web apps, content sites, admin-heavy products, startups that must move fast APIs, microservices, ML model serving, async workloads Small apps and prototypes

Both main frameworks are excellent; many companies use Django for the main product and FastAPI for specific services. The skills transfer: HTTP, routing, ORMs, validation and authentication work the same way everywhere.

Setting up a project on your computer

Always use a virtual environment per project (see the Python track's last lesson):

bash
python -m venv .venv
source .venv/bin/activate          # Windows: .venv\Scripts\activate

pip install "fastapi[standard]"    # FastAPI + uvicorn + extras
pip install django                 # or Django

Or with uv, the fast modern tool: uv init shop && cd shop && uv add "fastapi[standard]".

Practice

  1. Add a /time route to the WSGI app that returns a fixed time string.
  2. Change the ASGI app to return a 404 status for any path that doesn't start with /products.
  3. Decide which framework you'd pick for (a) a news site with editors, (b) an API that serves a machine-learning model, and explain why.
✎ Check your understanding

1.What is ASGI?

2.Which framework includes an ORM, migrations and an admin panel out of the box?

3.What does FastAPI use to validate request data?