在jinjia2中想直接用
{% for i in n %}
當前是第 x 條
{% endfor %}
是不行的。
{% for i, val in enumerate(['a', 'b', 'c']) %}
<td>
{{ val }}
</td>
{% endfor %}
報錯:
UndefinedError: 'enumerate' is undefined
Jinja2 has its own language. Looks like Python but it's not Python. So the Python enumerate built-in function is not part of Jinja2 template engine.
可以用以下方法

例如:
{% for chose in choses %}
<li>
<p>[第{{ loop.index}}題]{{ chose.content }}</p>
<p>A.{{ chose.a }}</p>
<p>B.{{ chose.b }}</p>
<p>C.{{ chose.c }}</p>
<p>D.{{ chose.d }}</p>
</li>
{% endfor %}
參考:https://segmentfault.com/q/1010000000690359/a-1020000000690397
