33👍
✅
Use for...empty
, which is basically the Django equivalent (replaces the else
keyword with empty
).
0👍
I know it’s a very old post. Adding an answer for future reference. There is no explicit way to achieve for..else
but we can do something like the following.
{% for x in some_list %}
... awesome html and more here
{% if forloop.last %}
... executes only if this is the last time through the loop
{% endif %}
{% endfor %}
Hope this helps. More reading here
- [Django]-How do Django models work?
- [Django]-Django – How to use decorator in class-based view methods?
- [Django]-Django: How to check if the user left all fields blank (or to initial values)?
Source:stackexchange.com