Displaying flash messages in DJango with close button
I want to display flash messages in Django using a close button. Django's existing message structure allows messages to be displayed and not to be closed.
As an example, web2py provides flash messages like this. I am looking for similar functionality in Django.
If it can be done with a few lines of code, that would be great. I don't want to add any other libraries or frameworks on top of Django.
Thanks in advance.
+3
source to share
2 answers
I didn't know that such a thing could be solved with a seat belt!
I did something like this:
{% if messages %}
{% for msg in messages %}
<div class="alert alert-info alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{msg.message}}
</div>
{% endfor %}
{% endif %}
+3
source to share