0

I have a view in which I send some messages, like this:

messages.warning(request, 'Nothing found")

In my settings.py I have edited the message tags like:

MESSAGE_TAGS = {
    messages.DEBUG: 'alert-info',
    messages.INFO: 'alert-info',
    messages.SUCCESS: 'alert-success',
    messages.WARNING: 'alert-warning',
    messages.ERROR: 'alert-danger'
}

on my template, I display them like this:

{% for message in messages %}
    <div class="alert {{ message.tags }} alert-dismissible fade in">
        <button type="button" class="close" aria-label="Close">
            <span aria-hidden="true">&times;</span>
        </button>
        {% if message.tags == 'info' %}
            <p>{{ message }}<br>
                You have <strong>{{users}}</strong> user{{users|pluralize}}<br>
         ,around <strong>{{non_users}}</strong> non user{{non_users|pluralize}}</p>
        {% else %}
            <p>{{ message }}</p>
        {% endif %}
    </div>
{% endfor %}

When the template loads, the messages appears very fast and disappears.

If I try this: <p>{{message}}</p> instead the message stays there, so I'm guessing I'm doing something wrong with bootstrap.

This (kinda) works as well: <div class="{{message.tags}}">

Could someone shed a light?

Edit:

I just noticed this is happening specifically when I use messages.error(), the rest of them are working properly, can't seem to find what's wrong.

Onilol
  • 1,315
  • 16
  • 41

1 Answers1

0

try this, the class is alert-{{tag}} which will render alert-info, there's no whitespace

{% for message in messages %}
    <div class="alert alert-{{message.tags}} page-alert">
        <button type="button" class="close" data-dismiss='alert'>
             <span aria-hidden="true"> × </span>
             <span class="sr-only">Close</span>
        </button>
        <p>{{message}}</p> 
    </div>
{% endfor %}
Lemayzeur
  • 8,297
  • 3
  • 23
  • 50