如何自动增加列表中的一项?
我有这样的东西:
data = {'端口': [22,80,443], '横幅': ['OpenSSH','Apache2','Apache'], '协议(protocol)': ['tcp','tcp','tcp' ] }
{% for key, value in data.items %}
<tr>
<th class="white">{{key}}</th>
<th class="black">{{value.0}}</th>
</tr>
{% endfor %}
如何将“value.0”自动增量为“value.1”、“value.2”等...
也许我可以用 forloop.counter0 来做到这一点?但如何呢?
谢谢!
最佳答案
您可以使用另一个 for
循环迭代这些值:
{% for key, value in ack.items %}
<tr>
<th class="white">{{key}}</th>
{% for v in value %}
<th class="black">{{v}}</th>
{% endfor %}
</tr>
{% endfor %}
关于python - 模板中的 django forloop 计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38491977/