2. Chapter overview
This page gives you the map for the chapter: the Flask ideas you will learn, the small files you will create, and the point where those pieces meet the Music Time Machine database.
The chapter moves in two passes. First, you learn the Flask building blocks in small, focused examples. Then, at the end, you use those same building blocks against the project you already have: a single route that reads music_time_machine.db and renders one real page.
Chapter 18 builds the full Music Time Machine dashboard, with cards, charts, browser login, and multiple sections. This chapter stays smaller on purpose. It teaches the web foundation first, so the dashboard build can focus on applying it.
What you'll learn
- Connect web addresses to Python functions with
@app.route() - Return simple text, HTML pages, redirects, and status codes from route functions
- Render pages with Jinja2 templates: variables, loops, conditionals, and autoescaping
- Share page structure with template inheritance and serve CSS through Flask's static-file system
- Read query strings and form submissions with Flask's
requestobject - Remember small pieces of state with
sessionand show one-time messages withflash() - Handle common errors and debug problems from both the terminal and the browser
What you'll build
app.py-- a small Flask app with routes, a form, session use, and error handlerstemplates/-- HTML templates, a shared base layout, and a reusable navigation includestatic/-- CSS and other browser assets served by Flask- A capstone page that reads
music_time_machine.dband shows real listening data, including an empty state for a fresh database