Django 模板语法之标签
1 for循环中自带的forloop 特点
1.1 准备
后端(views.py中)
l = [11, 22, 33, 44, 55, 66]
html页面中
1.2 特点:
2 for 循环
- 可以写一个for后按TAB键自动补全
{{ foo }}
{% endfor %} 3 if 语句 格式 4 for循环和if语句混合用法 实际演示 参考格式 {% for foo in l %} {% if forloop.first %}china
{% elif forloop.last %}READ
{% else %}{{ foo }}
{% endif %} {% empty %}for循环可迭代对象内部无元素,无法循环
{% endfor %} 5 for循环字典的k、v、或k-v 6 with起别名