How to check last loop iteration in Django template?

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

+81
django for-loop django-templates
May 7, '09 at 21:55
source share
2 answers

You would use forloop.last . For example:

 <ul> {% for item in menu_items %} <li{% if forloop.last %} class='last'{% endif %}>{{ item }}</li> {% endfor %} </ul> 
+194
May 7 '09 at 9:59 p.m.
source share

{{forloop.last}}

+10
May 07, '09 at 22:00
source share



All Articles