Escape
{% autoescape on %}
{{ body }}
{% endautoescape %}
Autoescape
{% autoescape off %}
{% firstof var1 var2 var3 "fallback value" %}
{% endautoescape %}
Comment
{% comment "Optional note" %}
Commented out text with {{ create_date|date:"c" }}
{% endcomment %}
Extends
{% extends "base.html" %}
Filter
{% filter force_escape|lower %}
This text will be HTML-escaped, and will appear in all lowercase.
{% endfilter %}
Firstof
{% firstof var1 var2 var3 %} {% firstof var1 var2 var3 "fallback value" %}
If
{% if athlete_list %}
Number of athletes: {{ athlete_list|length }}
{% elif athlete_in_locker_room_list %}
Athletes should be out of the locker room soon!
{% else %}
No athletes.
{% endif %}
Ifchanged
Archive for {{ year }}
{% for date in days %}
{% ifchanged %}
{{ date|date:"F" }}
{% endifchanged %}
{{ date|date:"j" }}
{% endfor %}
Include
{% include "foo/bar.html" %}
Load
{% load somelibrary package.otherlibrary %}
Lorem Either w for words, p for HTML paragraphs or b for plain-text paragraph blocks
{% lorem [count] [method] [random] %} # {% lorem 2 w random %}
Now
{% now "jS F Y H:i" %}
{% now "SHORT_DATETIME_FORMAT" %} # DATE_FORMAT, DATETIME_FORMAT, SHORT_DATE_FORMAT or SHORT_DATETIME_FORMAT
{% now "Y" as current_year %}
Regroup
-
{% for country in country_list %}
- {{ country.grouper }}
-
{% for city in country.list %}
- {{ city.name }}: {{ city.population }}
{% endfor %}
{% endfor %}
Spaceless / remove white space between HTML tags
{% endspaceless %} # will be
Url
With Caches a complex variable under a simpler name
{% with total=business.employees.count %}
{{ total }} employee{{ total|pluralize }}
{% endwith %}
# or decalare vaiables
{% with alpha=1 beta=2 %}
...
{% endwith %}