title: Displaying Django Messages Framework Messages
body: <p>I have been using the <a href="http://docs.djangoproject.com/en/dev/ref/contrib/messages/" rel="noreferrer">Django Messaging Framework</a> to display messages to a user in the template.</p>
  
  <p>I am outputting them to the template like this:</p>
  
  <pre><code>&lt;ul&gt;
      {% for message in messages %}
          &lt;li{% if message.tags %} class="{{ message.tags }}"{% endif %}&gt;{{ message }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>&lt;ul&gt;
      {% for message in messages.errors %}
          &lt;li&gt;{{ message }}&lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>The best I have come up with so far is this:</p>
  
  <pre><code>{% if messages %}
      {% for message in messages %}
          {% if forloop.first %}
              {% if message.tags == 'error' %}
                  &lt;div class="error"&gt;
                      &lt;ul&gt;
              {% endif %}
          {% endif %}
  
          &lt;li&gt;{{ message }}&lt;/li&gt;
  
          {% if forloop.last %}
                  &lt;/ul&gt;
              &lt;/div&gt;
          {% endif %}
      {% endfor %}
  {% endif %}
  </code></pre>
  
  <p>Any ideas?
  Thanks in advance.</p>