Skip to the workspace
Pebellslearn by building
Introduction to Django  ›  Lesson

How the Web Works

How the Web Works 12 minA browser sends an HTTP request naming a method and a path, a server sends back a response with a status code and a body, and Django is the program on the server that turns one into the other.

django / How the Web Works

Explore each scene at your own pace.

01 · The rule

The rule

How the Web Works

Before you write a line of Django, it helps to know the one conversation it takes part in, millions of times a day. A reader clicks a link to your cookbook site. Something travels out, something comes back, and a recipe appears. Django lives in the middle of that exchange, so this is the map for everything that follows.

The rule

The browser asks, the server answers: one request, one response.

Every page load is a short, polite exchange written in HTTP. The browser (the client) sends a request; the machine hosting the site (the server) sends back a response.

A request names a method (what you want to do) and a path (what you want it done to):

GET /recipes/tomato-soup/ HTTP/1.1
Host: cookbook.example.com
Accept: text/html

The response starts with a status code, then headers, then the body, usually HTML:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8

<h1>Tomato soup</h1>

The methods you will meet first are GET (fetch something, change nothing) and POST (send data, such as a new recipe from a form). Status codes come in families: 2xx worked (200 OK), 3xx go elsewhere (302 redirect), 4xx the client asked for something wrong (404 Not Found), 5xx the server broke (500).

HTTP is stateless: the server does not remember you between requests by itself. Sites that "know" you are logged in do it with a cookie the browser sends back with every request.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.