Handling requests
The framework receives an HTTP request and decides which code should handle it.
Simple syntax, a powerful ecosystem and mature frameworks make Python a convenient language to start web development with.
Just starting out? First go through the “From scratch” lessons, and look up unfamiliar words in the glossary.
The backend is the part of an application that runs on the server: it receives requests, handles the logic, talks to the database and sends a response.
The framework receives an HTTP request and decides which code should handle it.
The application reads and saves users, products, articles and other data through an ORM or SQL.
The server returns HTML, JSON or a file: what the user finally sees.
Checking data, access rights, handling errors and preparing a correct response.
The server receives requests, works with data and returns responses. This is what Python code does for that.
A simplified chain from the click to the server's response.
The user opens a page or submits a form.
The request goes to the server: method, address and data.
Django or Flask finds the right route and handler.
The code checks the data and reads or saves information.
The server returns a page, JSON or an error.
What happens in a split second after you press the “Add task” button.
POST /tasks request with headers, cookies and the form data./tasks and the POST method point to your function, which receives the request object.INSERT INTO tasks ... with parameters runs, and the database returns the new row's number.The main reasons the language stays a popular choice for server-side development.
| Feature | Why it matters |
|---|---|
| Readable syntax | Code is easier to maintain and review in a team, and beginners get in more easily. |
| Ready-made frameworks | Django and Flask cover most typical server-side tasks. |
| Library ecosystem | It is easy to add a database, authentication, API tools and analytics. |
| Link to data analysis | One language can be used for the web, automation and data analysis. |
A minimal Flask server and basic work with SQLite: two important entry points.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, this is a Python server!"
if __name__ == "__main__":
app.run()
import sqlite3
conn = sqlite3.connect("app.db")
cursor = conn.cursor()
cursor.execute(
"CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)"
)
cursor.execute(
"INSERT INTO users (name) VALUES ('Aigerim')"
)
conn.commit()
conn.close()
Note: the examples are for learning, and no server runs in this project. Here you can only read and copy the code.
Terms that help you read web development material with more confidence.
The server side of an application, which handles requests, stores data and returns responses.
The client side of a website: the interface, buttons, forms and everything the user sees in the browser.
The protocol the browser and server use to exchange requests and responses.
A tool that lets you work with a database through objects and code instead of hand-written SQL queries.
An interface through which one program can get data or functions from another program.
A lightweight database often used for learning and small projects.
What you can do after studying this section.
Four questions on this section. An explanation appears after you answer.
Checked on . The examples are for Python 3.12 and newer.
Once the basics are clear, the next step is to choose a framework: Django or Flask.
You open a page, the browser sends a request to the server, a Python program finds the data and sends back a response. Below is the same as a list.