About Generators in Django Templates

In Django templates, when you use generators and need the empty list condition, use the {% empty %} template tag:

{% for item in item_generator %}
    {{ item }}<br />
{% empty %}
    No items.
{% endfor %}

Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2