I was looking something similar to Bootstrap Alerts for using as flash message and came up with this - Flask-Toastr. I tried to import it but saw that it's not present so thought of installing it but got no command for installing via conda. Can anyone provide me the command for installation ?
Or can you give a better flash message display style.
Asked
Active
Viewed 1,584 times
1
Barefaced Bear
- 688
- 1
- 9
- 30
2 Answers
2
Why not just implement this natively. Flask supports a Flashing with Categroies...
You could pass the bootstrap class name as the category string:
flash(u'You are about to delete everything!', 'alert-danger')
Then handle this in the template. This is with Bootstrap 4.3's syntax for alerts...
{% with messages = get_flashed_messages(with_categories=true) %}
{% if messages %}
{% for category, message in messages %}
<div class="alert {{category}}" role="alert">
{{message}}
</div>
{% endfor %}
{% endif %}
{% endwith %}
This saves on introducing another dep for something simple.
v25
- 7,096
- 2
- 20
- 36
-
I am currently using bootstrap alert but looking to try something new so I came up with this – Barefaced Bear Oct 05 '19 at 00:14
-
1@BarefacedBear The `u` in front of the string was intentional. See [this question](https://stackoverflow.com/questions/2081640/what-exactly-do-u-and-r-string-flags-do-and-what-are-raw-string-literals) for an explanation. – Lord Elrond Oct 05 '19 at 00:26
-
I wish to use bootstrap toast instead of alerts. I replaced the contents with code for toast but does not seem to be working. Any idea ? – Amit Pathak Mar 27 '22 at 18:56