How Servers Build Pages
Static pages are just files; real apps *generate* pages from data. This is where your Python comes in โ routing a URL to code that pulls data, fills a template, and returns HTML.
A simple website is just static HTML files a server hands out. But real web apps are dynamic: they generate each page from data - your feed, your dashboard, your search results are built on the fly. This is exactly where your programming skills come in. The pattern is: a URL comes in, your code decides how to handle it (routing), pulls the right data, fills a template, and returns the HTML. This session is the heart of building web apps.
/posts/<slug> - and one template. When a request for /posts/how-i-learned-to-code arrives, the router matches it, the handler loads that post's data, fills the single template with it, and returns the finished HTML. Add a new post to the data and its page exists instantly, styled like all the others, with no new file written. That's the power of dynamic generation: routes and templates turn data into pages on demand, so a handful of code serves an unlimited number of pages. It's the same pattern behind every feed, dashboard and shop on the web.Routing: URL to code
The server needs to map each incoming URL to the code that handles it. That mapping is routing - the core of every web framework.
from larzrouter import Router
app = Router()
@app.route("/users/<int:id>")
def show_user(id):
user = load_user(id) # pull the data
return render_profile(user) # build the HTML
# a request for /users/42 -> show_user(id=42)/users/42 arrives, the router matches it to your show_user function and hands it the id (42). Your function then does the real work - fetch the user, build the response. This is the fundamental loop of a web app: URL in, matched to a handler, handler returns a response. The stack's larzrouter does exactly this, and it's the same idea at the core of every big web framework.Templates: data into HTML
Once your handler has the data, it turns it into HTML with a template - HTML with placeholders your data fills in - rather than gluing strings together.
from larztemplate import render
page = render(
"<h1>{{ user.name }}</h1>"
"{% for book in user.books %}<li>{{ book }}</li>{% endfor %}",
{"user": user},
)| Step | What happens |
|---|---|
| Request arrives | GET /users/42 |
| Router matches | -> show_user(id=42) |
| Handler gets data | load the user + their books |
| Template renders | data -> HTML |
| Response sent | the HTML goes back to the browser |
That five-step flow - request, route, data, template, response - is what a web app <i>is</i>. Everything else (databases, accounts, styling) hangs off this backbone. You already have all the pieces: functions, data handling, routing and templating.
The backbone of a web app
- Dynamic apps generate pages from data, not static files.
- Routing maps each URL to a handler function (larzrouter).
- The handler pulls the data and fills a template (larztemplate) to build HTML.
- Request -> route -> data -> template -> response is what a web app is.
๐งฉ Do it with LarzOS
Turn this lesson into action with the exact free tools and AI workflows for the job:
๐ฏ Key takeaways
- Real web apps are dynamic: they generate each page from data, not hand out static files.
- Routing maps an incoming URL to the handler function that should deal with it (larzrouter).
- The handler pulls the data and fills a template (larztemplate) to build the HTML response.
- Request -> route -> data -> template -> response is the backbone of every web app.
Frequently asked
What's the difference between a static website and a dynamic web app?
A static website is made of fixed files - HTML pages that were written ahead of time and are handed to every visitor exactly as they are, unchanged. Think of a simple brochure site or a basic blog where each page is a file sitting on the server: everyone sees the same thing, and to change a page someone edits the file. A dynamic web app, by contrast, generates its pages on the fly from data, so different users and different moments produce different pages. Your social media feed, your email inbox, a dashboard showing your data, search results for your query - none of those exist as pre-written files; they're built fresh each time by code that pulls the relevant data (your posts, your messages, the search matches) and assembles a page from it. That's the key difference: static serves fixed files, dynamic runs code to build pages per request. Dynamic is where the real value and complexity of web software lives, because it can respond to each user, show live data, handle input, and do genuinely useful work - and it's exactly what your programming skills let you build. The mechanism, as this session covers, is routing a request to a handler function, which fetches data and fills a template to produce the HTML. Many real sites blend both - static files for things that don't change (the logo, styling, an 'about' page) and dynamic generation for the parts that do (user-specific or data-driven pages) - and there are even techniques to pre-generate pages for speed. But the conceptual distinction is clear and important: static means serving pre-made files, dynamic means generating pages from data with code. Learning to build the dynamic kind is what turns you from someone who can make a web page into someone who can build a web application.
Frameworks like Flask or Django do routing and templating for me - why learn how it works?
Real frameworks absolutely handle routing, templating, and much more for you, and you'll use them for real projects - but understanding how those pieces work underneath makes you dramatically more effective with them, and that's why learning the mechanism matters. When you know that routing is fundamentally 'match a URL pattern to a function and extract the parts', and that templating is 'fill placeholders in HTML with your data', then a framework's routing and templating features stop being magic incantations you copy from tutorials and become tools you understand and can use confidently, debug when they misbehave, and reason about. You'll understand why a route isn't matching (the pattern doesn't fit the URL), why data isn't showing (it's not in the template's context), and how to structure your app, because you grasp the underlying request-route-data-template-response flow that every framework implements. It's the difference between a driver who understands roughly how a car works - who can handle problems and drive well - and one who only knows which pedals to press and is helpless the moment something's unusual. The Larz stack's larzrouter and larztemplate exist precisely to show you these core ideas in code you can read, so that when you move to a full framework, you recognise what it's doing and feel at home rather than overwhelmed. Frameworks also make many decisions and add conventions on top of these basics, and understanding the basics helps you tell the essential idea from the framework's particular flavour of it. So: yes, use frameworks - they save enormous effort and you shouldn't rebuild routing and templating from scratch for real projects - but learn how routing and templating work first, because that understanding transfers to every framework you'll ever use and turns you from someone following recipes into someone who genuinely understands web apps. The concepts are the durable knowledge; the specific framework is just one implementation of them.
Related lessons
HTML & CSS: Structure and Style
A web page is content (HTML) with styling (CSS) laid over it. You don't need to be a desigโฆ
Web Development BasicsHandling User Input (Safely)
The moment your app accepts input โ a form, a search box, an API call โ you're taking dataโฆ
Build Your First Real ProjectBuild the Core (One Piece at a Time)
Now you build โ but not all at once. Get the smallest piece working, then the next, keepinโฆ