← Django learning path
Django · Module 3 of 10

Templates

Generate HTML with the Django Template Language.

📖 Key ideas

  1. render(request, "blog/list.html", {"posts": posts}).
  2. Show variables: {{ post.title }}.
  3. Tags: {% for post in posts %} ... {% endfor %}, {% if %}.
  4. Template inheritance: {% extends "base.html" %} and {% block content %}.
  5. 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