I have been using the Django Messaging Framework to display messages to a user in the template.
I am outputting them to the template like this:
<ul>
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li>
{% endfor %}
</ul>
This outputs all the messages, errors, warning, success etc. I was just wondering if anyone had any ideas how to display only the error messages something like:
<ul>
{% for message in messages.errors %}
<li>{{ message }}</li>
{% endfor %}
</ul>
The best I have come up with so far is this:
{% if messages %}
{% for message in messages %}
{% if forloop.first %}
{% if message.tags == 'error' %}
<div class="error">
<ul>
{% endif %}
{% endif %}
<li>{{ message }}</li>
{% if forloop.last %}
</ul>
</div>
{% endif %}
{% endfor %}
{% endif %}
Any ideas? Thanks in advance.