BeginnerCoder

Lesson 5 — Templates

Templates fill HTML with data

A template is an HTML file with gaps for data. In Django you write {% for n in names %}<li>{{ n }}</li>{% endfor %} and Django fills in the values. Here we build the same HTML with Python strings.

"".join(...) glues many strings into one:

"".join(f"<b>{w}</b>" for w in ["A", "B"])   # <b>A</b><b>B</b>

Note: the exercise runs in your browser without Django installed, so it is a small plain-Python simulation of what Django does for you.

Why it matters: templates are how data from your views becomes the page the visitor actually sees.

Want it another way?
Task

Build html as <ul> + one <li> per name + </ul>, then print it.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.