Django
Feb 28, 2014 · Updated: Nov 10, 2017 · by Tim Kamanin
To make Django messages look nice in your bootstrap 3 template you need two
things:
@register.assignment_tag
def get_bootstrap_alert_msg_css_name(tags):
return 'danger' if tags == 'error' else tags
{% if messages %}
<ul class="list-unstyled messages">
{% for message in messages %}
{% get_bootstrap_alert_msg_css_name message.tags as alert_tag %}
<li class="alert alert-{{ alert_tag }}">{{ message }}</li>
{% endfor %}
</ul>
{% endif %}
Hey, if you've found this useful, please share the post to help other folks find it: