Question

I have a basic question, in the Django template language how can you tell if you are at the last loop iteration in a for loop?

Was it helpful?

Solution

You would use forloop.last. For example:

<ul>
{% for item in menu_items %}
    <li{% if forloop.last %} class='last'{% endif %}>{{ item }}</li>
{% endfor %}
</ul>

OTHER TIPS

{{ forloop.last }}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top