← Flask learning path
Flask · Module 3 of 10

Templates with Jinja2

Render dynamic HTML using Jinja2 templates.

📖 Key ideas

  1. Put templates in templates/ folder.
  2. render_template("index.html", name=name).
  3. {{ name }} prints; {% for %} and {% if %} control logic.
  4. Inheritance with {% extends "base.html" %} and {% block %}.
  5. Static files go in static/; link with url_for("static", filename="style.css").
💡 Real-life example: Jinja2 is a mail-merge: one letter design, filled with each person's details.
Jinja2Template engine used by Flask
render_templateRenders a template with data
blockReplaceable area in a base template
static/Folder for CSS, JS, images