Change color of flask.flash messages

Question:

Is it possible to change the color of flask.flash messages? The message is currently written in black and in very small characters.

Asked By: Yoav.L

||

Answers:

Flask messages takes optional argument called category and use this to update template as you like.

flash('This is error message', 'error')

And in your html do remember to add with_categories option

{% with messages = get_flashed_messages(with_categories=true) %}
  {% for category, message in messages %}
    <div class="{{ category }}">{{ message }}</div>
  {% endfor %}
{% endwith %}

Also please include this in your stylesheet

.error {
    color: red
}
Answered By: Raja Simon

An easier way would be to just wrap the actual message in a paragraph

and not a list item element

  • i.e.: <p>{{ message }}</p>
    See illustration below.

    <!doctype html>
    <title>My Application</title>
    {% with messages = get_flashed_messages() %}
        {% if messages %}
        <ul class=flashes>
            {% for message in messages %}
            <p>{{ message }}</p>
            {% endfor %}
        </ul>
        {% endif %}
    {% endwith %}
    

    {% block body %}{% endblock %}

  • Answered By: AbdulHafeez
    Categories: questions Tags: ,
    Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
    at the top-right corner.