pythonflask

Change color of flask.flash messages


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


Solution

  • 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
    }