Template engine.

Django ships with its own template engine (DTL). A template is a text file mixing static content with special constructs that are evaluated at render time against a context (a dictionary of variables).

Blocks

{% block name %}...{% endblock %} defines a region a child template can override. Combined with {% extends %} it powers template inheritance and the DRY principle: this very page overrides the style block to load a different stylesheet.

For loops

{% for item in list %} {{ item }} {% endfor %} iterates over any iterable passed in the context.

If control structures

{% if condition %}...{% elif other %}...{% else %}...{% endif %} renders content conditionally.

Displaying context variables

A variable is printed with double curly braces: {{ variable }}, and filters transform it: {{ name|upper }}.