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/htmlThe 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.
The shortcut
Read any URL as where + what: the domain says which server, the path says what to ask it for, and anything after ? is extra detail for that request. Then remember that each file on a page is its own round trip.
Find the server
The browser asks DNS for the address behind
cookbook.example.comand connects to it.
The common mix-up is thinking the server "sends the website" once. It sends one response per request, and a single page may need a dozen.
Drills
Answer fast — trust the rule.
In https://cookbook.example.com/recipes/?page=2, which part is the path?
A reader asks for a recipe that does not exist. Which status code fits?
Which method should a "Save new recipe" form use?
A page's HTML links one stylesheet and three images, and nothing is cached. How many requests does the browser make?
HTTP is stateless. How does a site still recognise that you are logged in?
Remember
- One request, one response: method + path in, status code + body out.
- Read a URL as where (domain) + what (path), then extras after
?. - Every file on a page is its own round trip; Django builds the responses on the server.
