1. 模板变量之forloop.counter
:从1开始自增1
{% for row in v %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{row.hostname}}</td>
<td>{{row.ip}}</td>
<td>{{row.port}}</td>
<td>{{row.b.caption}}</td>
<td>{{row.b.code}}</td>
</tr>
{% endfor %}
- 浏览器效果
2. 模板变量之forloop.counter0
:从0开始自增1
{% for row in v %}
<tr>
<td>{{forloop.counter0}}</td>
<td>{{row.hostname}}</td>
<td>{{row.ip}}</td>
<td>{{row.port}}</td>
<td>{{row.b.caption}}</td>
<td>{{row.b.code}}</td>
</tr>
{% endfor %}
- 浏览器效果
3. 模板变量之forloop.revcounter
:从循环最大值开始自减1,自减到1截止
{% for row in v %}
<tr>
<td>{{forloop.revcounter}}</td>
<td>{{row.hostname}}</td>
<td>{{row.ip}}</td>
<td>{{row.port}}</td>
<td>{{row.b.caption}}</td>
<td>{{row.b.code}}</td>
</tr>
{% endfor %}
- 浏览器效果:
4. 模板变量之forloop.revcounter0
:从循环最大值开始自减1,自减到0截止
{% for row in v %}
<tr>
<td>{{forloop.revcounter0}}</td>
<td>{{row.hostname}}</td>
<td>{{row.ip}}</td>
<td>{{row.port}}</td>
<td>{{row.b.caption}}</td>
<td>{{row.b.code}}</td>
</tr>
{% endfor %}
- 浏览器效果:
5. 模板变量之forloop.first
:是否是第一次循环
{% for row in v %}
<tr>
<td>{{forloop.first}}</td>
<td>{{row.hostname}}</td>
<td>{{row.ip}}</td>
<td>{{row.port}}</td>
<td>{{row.b.caption}}</td>
<td>{{row.b.code}}</td>
</tr>
{% endfor %}
- 浏览器效果:
6. 模板变量之forloop.last
:是否是最后一次循环
{% for row in v %}
<tr>
<td>{{forloop.last}}</td>
<td>{{row.hostname}}</td>
<td>{{row.ip}}</td>
<td>{{row.port}}</td>
<td>{{row.b.caption}}</td>
<td>{{row.b.code}}</td>
</tr>
{% endfor %}
- 浏览器效果:
7. 模板变量之forloop.parentloop
:获取父级循环对象,同时也拥有:counter/counter0/revcounter/revcounter0/first/last 等属性