16๐
โ
{% for shelf in final_shelf_info %}
{% if forloop.first %}
Do something with {{ shelf }} since its the first item iterated
{% endif %}
{% endfor %}
More on the {% for %}
template loop in the docs.
๐คnik_m
4๐
You could do something like this:
{% for t in things %}
{% if forloop.first %}
// do something
{% endif %}
// do stuff
{% if forloop.last or things.count == 1 %}
// do something
{% endif %}
{% endfor %}
More documentation is available at Django documentation
๐คuser4426017
- [Django]-Appending a queryset to a list/tuple without evaluating it
- [Django]-DRF: Always apply default permission class
- [Django]-Hosting Admin Media Locally During Development
- [Django]-How to get tests coverage using Django, Jenkins and Sonar?
- [Django]-Create Docker container with Django, npm and gulp
Source:stackexchange.com