Templates for Flasks
Flask templates are Jinja files that mix HTML with placeholders, loops and conditions, rendered on the server with render_template. They sit between your view functions and the browser, turning Python data into finished pages, and they support inheritance so layouts such as headers and footers are written only once.
Stage: Quickstart · Part of the Flask roadmap · Last reviewed 19 November 2026
What to learn in Templates
- Render an HTML file from a view with render_template and context variables
- Use Jinja expressions, if blocks and for loops to display data
- Build a base layout and extend it with block and extends tags
- Apply filters and write a custom filter for formatting values
- Explain why Jinja autoescaping protects pages from injected markup
Templates interview questions
Why does Jinja autoescape variables and when would you disable it?
Autoescaping converts characters such as angle brackets into HTML entities so user input cannot inject scripts into the page. You should disable it only for content you have already sanitised, using the safe filter or Markup, because switching it off for raw input creates a cross-site scripting hole.
How does template inheritance work in Flask?
A base template defines named block sections. A child template starts with an extends tag pointing to the base and fills in only the blocks it needs to change. This keeps navigation, styles and footers in one file instead of repeating them on every page.
Where Templates fits in the Flask roadmap
Templates belongs to the Quickstart stage (beginner level), which takes about 17 hours. Your first app.
Other units in this stage
Back to the full Flask roadmap