标签:ref ever end play and lsh controls sed com
遍历每一个元素:
{% for person in person_list %} <p>{{ person.name }}</p> {% endfor %}
可以利用{% for obj in list reversed %}
反向完成循环。
遍历一个字典:
{% for key,val in dic.items %} <p>{{ key }}:{{ val }}</p> {% endfor %}
注:循环序号可以通过{{forloop}}显示
{% for person in person_list %} <p>{{ forloop.counter }} {{ person.name }},{{ person.age }}</p> <!-- counter0从0开始 --> {% endfor %}
for标签带有一个可选的
{% for person in person_list %} <p>{{ person.name }}</p> {% empty %} <p>sorry,no person here</p> {% endfor %}
参考:
https://www.cnblogs.com/lshedward/p/10351148.html
标签:ref ever end play and lsh controls sed com
原文地址:https://www.cnblogs.com/sea-stream/p/13326746.html