04模板标签与模板继承和引用
1.常用的模板标签 {% %}
-作用是什么? 对模板的变量引用进行循环,判断等逻辑运算
{% tag %} {% endtag %} / {% tag 参数 参数 %}
-
for循环 endfor / for…in
{% for stu in students %} <tr> <td>{ { forloop.counter}}</td> <td>{ { stu.name }}</td> <td>{ { stu.age }}</td> <td>{ { stu.gender }}</td> </tr> {% endfor %}
- forloop.counter 获得for循环的循环次数,以1为开始 .counter0,以0开始
- forloop.recounter 倒序循环次数,到1为止 .recounter0,到0为止
- forloop.first 返回布尔类型,是否为第一次循环
- forloop.last 返回布尔类型,是否为最后一次循环
- forloop.parentloop 返回父级循环
-
if,elif,else条件 endif