BeginnerCoder

Lesson 7 — Template rendering

Placeholders in text

A template has placeholders that are replaced by values at render time ("render" = produce the final text). Django uses {{ name }}; Python's built-in str.format uses {name}, which is a good model of the same idea:

"Hi, {name}!".format(name="Sam")   # Hi, Sam!

You can have several placeholders, each filled by a keyword argument.

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: the same template is reused for every user — only the values change.

Want it another way?
Task

Render the template for Sam with 3 new messages, so it prints: Hello, Sam! You have 3 new messages.

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.