IF 标签
{% if
user.age < 18 %}
html
{% else %}
html
{% endif %}
-------------------
{% if not user1 %}
html user 不存在
...
--------------------
{% if not user.name %}
判断字符是否为空, 数值是否为0
--------------------
FOR 标签
{% for %}
...
{% endfor %}
例子
{% for user in userList %}
html user
{% endfor %}
--------
反向输出
{% for user in userList reversed%}
-----------
为空的情况
{% for user in userList %}
html user
{% empty %}
html for empty
{% endfor %}
--------------
{% for key in userDict %}
html key
{% endfor %}
----------
{% for key, value in userDict.items %}
html key, value
{% endfor %}
-----------
forloop属性
循环的计数器
{{forloop.counter}} 1 2 3 4
{{forloop.counter0}} 01 2 3
{{forloop.revounter}} 4 3 2 1
{{forloop.revcounter0}} 3 2 1 0
例子
{% if forloop.first %}...
{% if forloop.last %}....
我的更多文章:
- (2016-04-05 10:18:36)
- (2016-04-05 09:41:37)
- (2016-04-04 20:38:37)
- (2016-04-04 20:01:09)
- (2016-04-04 16:34:28)