Django messages and twitter bootstrap 3 in templates
Unfortunately some alert names in twitter bootstrap o not match with django error messages, so here at nomadblue.com we use a simple template tag to return the proper twitter bootstrap alert class:
@register.assignment_tag
def get_twitter_bootstrap_alert_msg_css_name(tags):
return 'danger' if tags == 'error' else tags
Usage:
<ul class="messages">
{% for message in messages %}
{% get_twitter_bootstrap_alert_msg_css_name message.tags as alert_tag %}
<li class="alert alert-{{ alert_tag }}">{{ message }}</li>
{% endfor %}
</ul>
Written by Hector Garcia
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#