Lazo Lab Sign up

App 7: Your First Website with Flask / Build a guestbook website

Lesson 2 of 10

Templates

Writing HTML inside Python gets messy. Put HTML in a templates folder and use render_template. Jinja lets you insert values with {{ }}.

Key points

  • templates/index.html
  • render_template("index.html", name=...)
  • {{ name }} prints a value safely
# app.py
from flask import render_template

@app.route("/")
def home():
    return render_template("index.html", name="Lazo")

<!-- templates/index.html -->
<h1>Hello, {{ name }}!</h1>

Your turn

Move your page into templates/index.html and pass in your name.

Watch a video on thisOpens YouTube search results for “Templates” in a new tab

Quiz · +10 XP

Where does Flask look for templates?

Log in to save progress and earn XP.