Have a look at the {% empty %} tag.
Example from the documentation
<ul>
{% for athlete in athlete_list %}
<li>{{ athlete.name }}</li>
{% empty %}
<li>Sorry, no athletes in this list.</li>
{% endfor %}
</ul>
Link: https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#for-empty
If you are interested in a table, or some kind of heading if there are results, add the forloop.first
:
-
{% for athlete in athlete_list %}
- {{ athlete.name }}
- Sorry, no athletes in this list.
{% if forloop.first %}
Athlete Name:
{% endif %}
{% empty %}
{% endfor %}