Python Flask-Flash Categories

Flash Categories

To provide categories when flashing a message is possible. If nothing is provided then 'message' it is a default category. There are alternative categories that can be used to give the user better feedback.
Use the second argument to the flash() function to flash a message with different category:
flash(u'Invalid password provided', 'error')
Inside the template, you then have to tell the get_flashed_messages() function to also return the categories. The loop looks slightly different in that situation then:
{% with messages = get_flashed_messages(with_categories=true) %}
  {% if messages %}
    <ul class=flashes>
    {% for category, message in messages %}
      <li class="{{ category }}">{{ message }}</li>
    {% endfor %}
    </ul>
  {% endif %}
{% endwith %}

Use the category to add a prefix such as <strong>Error:</strong> to the message. This shows how to render these flashed messages.