{% firstof var1 var2 var3 %}{%for athlete in athlete_list %}<li>{{ athlete.name }}</li>{% endfor %}{%for x, y in points %}
There is a point at {{ x }},{{ y }}{% endfor %}{%for key, value in data.items %}{{ key }}:{{ value }}{% endfor %}
forloop.counter
forloop.counter0
forloop.revcounter
forloop.revcounter0
forloop.first
forloop.last
forloop.parentloop
{%for athlete in athlete_list %}<li>{{ athlete.name }}</li>{% empty %}<li>Sorry, no athletes in this list.</li>{% endfor %}{%filter force_escape|lower %}
This text will be HTML-escaped,and will appear inall lowercase.{% endfilter %}{% extends "./my/base3.html"%}{%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 %}{%if athlete_list and coach_list %}{%ifnot athlete_list %}{%if athlete_list or coach_list %}{%ifnot athlete_list or coach_list %}{%if athlete_list andnot coach_list %}
the operators ==,!=,<,>,<=,>=,in,notin,is# 跟过滤器的组合使用{%if messages|length >=100%}
You have lots of messages today!
{% endif %}# 加载自定义标签% load somelibrary package.otherlibrary %}# 引入模板{% include "name_snippet.html"%}#比较标签 ifequal and ifnotequal{% ifequal a b %}...{% endifequal %}
# 检查值是否发生改变 ifchanged
{%for date in days %}{% ifchanged %}<h3>{{ date|date:"F"}}</h3>{% endifchanged %}<a href="{{ date|date:"M/d"|lower }}/">{{ date|date:"j"}}</a>{% endfor %}
# 当前时间
{% now "jS F Y H:i"%}
# 关于随机生成的模板
{% lorem [count][method][random]%}
count A number (or variable) containing the number of paragraphs or words to generate (default is1).
method Either w for words, p for HTML paragraphs or b for plain-text paragraph blocks (default is b).
random The word random, which if given, does not use the common paragraph (“Lorem ipsum dolor sit amet…”) when generating text.# 对数据进行自动分类展示 regroup{% regroup cities by country as country_list %}<ul>{%for country in country_list %}<li>{{ country.grouper }}<ul>{%for city in country.list%}<li>{{ city.name }}:{{ city.population }}</li>{% endfor %}</ul></li>{% endfor %}</ul># resetcycle 重新遍历# 移除标签中的空白{% spaceless %}<p><a href="foo/">Foo</a></p>{% endspaceless %}# url{% url 'some-url-name' v1 v2 %}# templatetag{% templatetag openblock %} url 'entry_list'{% templatetag closeblock %}
openblock {%
closeblock %}
openvariable {{
closevariable }}
openbrace {
closebrace }
opencomment {#
closecomment #}# 普遍用在js模板中,避免跟django冲突{% verbatim %}{{if dying}}Still alive.{{/if}}{% endverbatim %}% verbatim myblock %}
Avoid template rendering via the {% verbatim %}{% endverbatim %} block.{% endverbatim myblock %}# 获取最大值<img src="bar.png" alt="Bar"
height="10" width="{% widthratio this_value max_value max_width %}"># 获取比较后的变量{% widthratio this_value max_value max_width as width %}{% blocktrans %}The width is:{{ width }}{% endblocktrans %}# with对值进行变量命名{%with total=business.employees.count %}{{ total }} employee{{ total|pluralize }}{% endwith %}