Django Messages do not disappear

Viewed 521

I'm facing the issue that on some browsers my Django messages do not disappear. For example, if a new post gets created the side indicates with a message that the new post has been successfully created. If I reload the page the message doesn't disappear and keeps showing up, why is that?

The issue goes so far that messages are stacking after using the side for a while you only see messages xD ...

Can somebody help with this? Is this just because of the browser that is being used?

This is how I display my messages:

<div class="messages">
    {% if messages %}
        {% for message in messages %}
            <span><li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li></span>
        {% endfor %}
    {% endif %}
</div>

Thanks in advance

1 Answers

Please try this

In your template

{% for message in messages %}
     {%if "hello" in message.tags %}
          <p class="messages alert alert-success" style="text-align: center;">  {{message}} </p> 
     {% endif %}
{% endfor %}

views.py

messages.warning(request, 'Insert whatever msg you want here.', extra_tags='hello')
Related