A web framework turns HTTP requests into Python function calls. You write functions; the framework figures out which one runs for a given URL and method, then ships whatever it returns back to the browser. Flask, Django and FastAPI are the three you'll meet most.
Where you meet it
- Building a JSON API for an app or a frontend to call.
- Serving HTML pages — a blog, a dashboard, an admin panel.
- Anything where a browser or client sends a request and expects a response.
What it does
It handles the boring, repetitive parts of talking HTTP: parsing the incoming request, matching it to your code, and packaging your return value as a proper response (status code, headers, body). You write the logic; it wires it to the web.
A framework is just routing plus glue — pick it for the job, and remember async only pays off when you actually await I/O.
How it works
The core idea is routing: the framework maps a URL + HTTP method to a handler function. The handler runs and returns a value, which becomes the response.
# Flask — a route, a handler, a response
from flask import Flask
app = Flask(__name__)
@app.route("/users/<int:id>") # method (GET) + path
def get_user(id): # the handler
return {"id": id} # becomes a JSON response
The three frameworks make different bets:
- Flask — a micro-framework. Minimal core, you add what you need. Great when you want to keep it small and explicit.
- Django — batteries-included. Ships an ORM, admin, auth, forms and a URL dispatcher (
path("users/<int:id>/", view)). Great for full sites where you don't want to assemble the pieces yourself. - FastAPI — async-first and built on type hints. The same hints that document your code also validate the request and auto-generate interactive API docs.
Under the hood, frameworks plug into a web server through a standard interface. WSGI is the older, synchronous one (Flask, Django classically). ASGI is its async successor — it can handle long-lived connections like WebSockets, which WSGI's one-call-per-request design can't (FastAPI runs on ASGI).
Watch out
- Pick the framework for the job, not the hype. A small HTML site doesn't need async; a high-concurrency API doesn't need Django's full stack.
- Async isn't free.
asynconly helps when you actuallyawaitI/O. Sync code in an async handler still blocks the worker. - The development server is not for production. Flask's built-in server and debugger run arbitrary code — deploy behind a real server (Gunicorn, Uvicorn) instead.
Go deeper
Ein Web-Framework verwandelt HTTP-Anfragen in Aufrufe von Python-Funktionen. Du schreibst Funktionen; das Framework entscheidet, welche für eine gegebene URL und Methode läuft, und schickt deren Rückgabewert zurück an den Browser. Flask, Django und FastAPI sind die drei, die dir am häufigsten begegnen.
Wo es vorkommt
- Eine JSON-API bauen, die eine App oder ein Frontend aufruft.
- HTML-Seiten ausliefern — ein Blog, ein Dashboard, ein Admin-Bereich.
- Überall, wo ein Browser oder Client eine Anfrage schickt und eine Antwort erwartet.
Was es tut
Es übernimmt die langweiligen, sich wiederholenden Teile der HTTP-Kommunikation: die eingehende Anfrage parsen, sie deinem Code zuordnen und deinen Rückgabewert als saubere Response verpacken (Statuscode, Header, Body). Du schreibst die Logik; das Framework verdrahtet sie mit dem Web.
Ein Framework ist nur Routing plus Klebstoff — wähle es zur Aufgabe, und async zahlt sich nur aus, wenn du wirklich I/O awaitest.
Wie es funktioniert
Die Kernidee ist Routing: Das Framework bildet eine URL + HTTP-Methode auf eine Handler-Funktion ab. Der Handler läuft und gibt einen Wert zurück, der zur Response wird.
# Flask — Route, Handler, Response
from flask import Flask
app = Flask(__name__)
@app.route("/users/<int:id>") # Methode (GET) + Pfad
def get_user(id): # der Handler
return {"id": id} # wird zur JSON-Response
Die drei Frameworks setzen auf Unterschiedliches:
- Flask — ein Micro-Framework. Minimaler Kern, du ergänzt, was du brauchst. Stark, wenn es klein und explizit bleiben soll.
- Django — batteries-included. Bringt ORM, Admin, Auth, Formulare und einen URL-Dispatcher mit (
path("users/<int:id>/", view)). Stark für vollständige Sites, bei denen du die Teile nicht selbst zusammenstecken willst. - FastAPI — async-first und auf Type Hints gebaut. Dieselben Hints, die deinen Code dokumentieren, validieren auch die Anfrage und erzeugen automatisch eine interaktive API-Doku.
Unter der Haube binden sich Frameworks über eine Standard-Schnittstelle an den Webserver. WSGI ist die ältere, synchrone (klassisch Flask, Django). ASGI ist ihr asynchroner Nachfolger — er kann langlebige Verbindungen wie WebSockets bedienen, was WSGIs Ein-Aufruf-pro-Anfrage-Design nicht kann (FastAPI läuft auf ASGI).
Worauf achten
- Wähle das Framework zur Aufgabe, nicht zum Hype. Eine kleine HTML-Seite braucht kein async; eine API mit hoher Nebenläufigkeit braucht nicht Djangos vollen Stack.
- Async ist nicht gratis.
asynchilft nur, wenn du tatsächlich I/Oawaitest. Synchroner Code in einem async-Handler blockiert den Worker trotzdem. - Der Entwicklungs-Server ist nicht für Produktion. Flasks eingebauter Server und Debugger führen beliebigen Code aus — deploye hinter einem echten Server (Gunicorn, Uvicorn).



