Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change color of flask.flash messages

Tags:

python

flask

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

like image 669
Yoav.L Avatar asked Jun 15 '17 13:06

Yoav.L


People also ask

How do I customize flash messages in Flask?

Its easy one. first do not concentrate on styling the error message. If your flash message works then add the flash('your_message', category="your_error_argument") add the with_categories=True in template that's it.


1 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
}
like image 130
Raja Simon Avatar answered Sep 28 '22 04:09

Raja Simon