I have a basic question, in the Django template language how can you tell if you are at the last loop iteration for a "for loop"?
我有一个基本的问题,在Django模板语言中,您如何知道您是否处于for循环的最后一个循环迭代中?
2 个解决方案
#1
167
You would use forloop.last
. For example:
你会使用forloop.last。例如:
<ul>
{% for item in menu_items %}
<li{% if forloop.last %} class='last'{% endif %}>{{ item }}</li>
{% endfor %}
</ul>
#2
9
{{ forloop.last }}
{ { forloop。去年} }
#1
167
You would use forloop.last
. For example:
你会使用forloop.last。例如:
<ul>
{% for item in menu_items %}
<li{% if forloop.last %} class='last'{% endif %}>{{ item }}</li>
{% endfor %}
</ul>
#2
9
{{ forloop.last }}
{ { forloop。去年} }