Django-bootstrap3: django messages framework message tags

Created on 7 Feb 2014  ·  4Comments  ·  Source: zostera/django-bootstrap3

the old bootstrap2 had a 1-1 mapping with django messages, so you could write:
class= {{message.tags }}-alert

Now 'error' changed to 'danger' in bs3, so any way this app can compensate for that? I added it manually. Is that the best way to handle that or could you squeeze this in to this app?

    {% for message in messages %}
        <div{% if message.tags %} class="alert alert-{{ message.tags }} {% if message.tags = 'error' %}alert-danger{%endif%}"{% endif %}>
            <button type="button" class="close" data-dismiss="alert">&times;</button>
        {{ message|safe }}
        </div>
    {% endfor %}

Most helpful comment

In your django settings add the following:

# needed to make this work with bootstrap labels
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
    messages.ERROR: 'danger'
}

All 4 comments

In your django settings add the following:

# needed to make this work with bootstrap labels
from django.contrib.messages import constants as messages
MESSAGE_TAGS = {
    messages.ERROR: 'danger'
}

This is for sure a lot cleaner, thanks!

This seems like the best way.

I think this one has to be reopened. If you override in MESSAGE_TAGS the level id displayed wrong in the admin panel. Furthermore, you should use message.level_tag instead of message.tags because message.tags could be 'customtag warning'.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kutera picture kutera  ·  8Comments

Macainian picture Macainian  ·  6Comments

jayvdb picture jayvdb  ·  7Comments

jacquev6 picture jacquev6  ·  3Comments

ghost picture ghost  ·  3Comments