Kahibaro
Discord Login Register

How the web works (basic overview)

The Big Picture: How the Web Works

When you build web apps with Python, you are really joining a big conversation between browsers and servers. To understand what your Python code is doing, you need a mental model of that conversation.

This section gives you a beginner-friendly overview of:

The Journey of a Web Page Request

When you type something like:

https://example.com/about

into your browser and press Enter, a lot of things happen very quickly. Simplified, the flow looks like this:

  1. You (the user) type a web address into the browser.
  2. The browser figures out which server to contact.
  3. A request is sent over the internet to that server.
  4. The server (often running Python) receives the request.
  5. The server decides what content to send back (HTML, images, etc.).
  6. A response is sent back to your browser.
  7. The browser displays the page for you.

You can think of it like sending a letter (the request) to a company (the server) and getting a reply (the response) with the information you asked for.

The Main Players: Browser, Server, Internet

Browser (Client)

When you build a Python web app, your code usually runs on the server, not in the browser.

Server

The browser never runs your Python code directly. Instead, the server runs Python, generates content (usually HTML), and sends that content to the browser.

The Internet (The Network in Between)

You can think of the internet as a huge postal system and road network:

URLs: Web Addresses

A web address like:

https://example.com:443/about?lang=en#team

is called a URL (Uniform Resource Locator). It has parts:

For web development, you will often focus on:

In Python frameworks, you’ll map paths (like /about) to functions in your code.

HTTP: The Language of the Web

HTTP (HyperText Transfer Protocol) is the main protocol used for web communication. It defines how clients and servers talk.

Requests and Responses

The web is based on a simple pattern:

A Simple HTTP Request (conceptual)

When you visit https://example.com/about, your browser might send a request like:

GET /about HTTP/1.1
Host: example.com
User-Agent: MyBrowser
Accept: text/html

Important parts:

A Simple HTTP Response (conceptual)

The server might answer with:

HTTP/1.1 200 OK
Content-Type: text/html
<html>
  <body>
    <h1>About This Site</h1>
  </body>
</html>

Important parts:

Common HTTP Methods (High Level)

You’ll see these methods a lot:

In your Python web apps, you will write code that behaves differently based on the method (for example, GET vs POST).

HTTP Status Codes (High Level)

Servers respond with status codes to indicate what happened:

As a Python web developer, you’ll often:

Static vs Dynamic Content

Not all pages are created the same way.

Static Content

For example, a static HTML file:

about.html

When requested, the server just sends it as-is.

Dynamic Content

For example, a Python function might:

  1. Read from a database.
  2. Insert that information into an HTML template.
  3. Return the final HTML to the browser.

Most modern web apps use a lot of dynamic content.

Where Python Fits In

When you write web apps with Python:

Conceptually:

  1. Browser sends a request: GET /hello.
  2. The server (with Python) receives it.
  3. Python code runs something like:
   def hello():
       return "<h1>Hello, world!</h1>"
  1. The server sends that HTML back to the browser.
  2. The browser shows "Hello, world!" to the user.

You’ll soon see how frameworks like Flask make this routing from URL → Python function easy to set up.

Client-Side vs Server-Side

Two main “sides” work together in a web app:

Server-Side (Where Python Lives)

Client-Side (In the Browser)

Your Python code focuses on the server-side. The browser never sees your Python source code; it only sees the final HTML, CSS, JavaScript, images, etc.

Stateful Users on a Stateless Protocol

HTTP itself is stateless:

But web apps feel like they have memory: you can log in, stay logged in, keep items in a shopping cart, etc. This is done using things like:

The important idea for now: your Python code helps “add state” on top of a stateless protocol so your app can remember users and their data across multiple requests.

Putting It All Together (Conceptual Flow)

Here’s a simple flow for a Python-based web app:

  1. You enter a URL in the browser: https://myapp.com/profile.
  2. Browser sends an HTTP GET request for /profile.
  3. The server receives /profile and passes it to your Python app.
  4. Your Python function:
    • Checks who is logged in.
    • Fetches their data from a database.
    • Inserts that data into an HTML template.
  5. Python returns the final HTML to the server.
  6. The server sends an HTTP response with status 200 and Content-Type: text/html.
  7. The browser displays the personalized profile page.

In the next sections of this chapter’s parent topic, you’ll start using a specific tool (Flask) to implement this flow in real code.

Views: 15

Comments

Please login to add a comment.

Don't have an account? Register now!