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.
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
}
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 %}
Is it possible to change the color of flask.flash
messages? The message is currently written in black and in very small characters.
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
}
An easier way would be to just wrap the actual message in a paragraph
and not a list item element
<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 %}