← Django learning pathDjango · Module 3 of 10
Templates
Generate HTML with the Django Template Language.
📖 Key ideas
- render(request, "blog/list.html", {"posts": posts}).
- Show variables: {{ post.title }}.
- Tags: {% for post in posts %} ... {% endfor %}, {% if %}.
- Template inheritance: {% extends "base.html" %} and {% block content %}.
- Variables are auto-escaped to prevent XSS.
💡 Real-life example: Template inheritance is a letterhead: every page uses the same header and footer, only the body changes.
{{ }}Outputs a variable
{% %}Template tag for logic
extendsInherit a base template
FilterModifies output like |date or |upper