djula
djula copied to clipboard
Provide an empty tag for use with for loops
Provide an empty tag for use with for loops, this would be useful if a loop failed to start.
For example
{% for x in y %}
<p>{{ x }}</p>
{% empty %}
<p>Nothing to show</p>
{% endfor %}
Hello, strange to me but interesting. Does this exist in Django? (I don't thing so) It can be done with a if tag of course, thus adding a level of nesting.
It does exist in django https://docs.djangoproject.com/en/5.1/ref/templates/builtins/#for-empty
I did think of simply nesting it using an if, but this is how django does it, however this also comes from the fact that python has optional else blocks that can be attached to loops.