Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
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.

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.

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.

One click on the cookbookStep 1 of 4
  1. Find the server

    The browser asks DNS for the address behind cookbook.example.com and 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.

quick drill

In https://cookbook.example.com/recipes/?page=2, which part is the path?

quick drill

A reader asks for a recipe that does not exist. Which status code fits?

quick drill

Which method should a "Save new recipe" form use?

quick drill

A page's HTML links one stylesheet and three images, and nothing is cached. How many requests does the browser make?

quick drill

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.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainFollow one click

A reader clicks a link to https://cookbook.example.com/recipes/tomato-soup/. Describe, in order, what happens until the recipe appears on screen, and say which part of that journey Django is responsible for.