user3595632
user3595632

Reputation: 5730

Django: How can I remove all stored messages?

I used django message framework only in one view(PasswordChangeView).

Problem is that when I access to PasswordChangeView, this page shows all message in message storage such as Login successed, Logout success etc...

This is my template.html:

{% for message in messages %}
    <p {% if message.tags %} class="alert alert-{{ message.tags }} messages"{% endif %}> {{ message }} </p>
{% endfor %}

I want to make PasswordChangeView show message only about password, not login, logout kinda thing.

How can I do this?

Upvotes: 0

Views: 371

Answers (1)

Brendan Metcalfe
Brendan Metcalfe

Reputation: 803

One way is to create 2 empty files templates/account/messages/logged_in.txt and templates/account/messages/logged_out.txt

It basically overwrites the login/logout messages.

Another way is to check in the template, such as:

--- Your code ---
{% if "signed" in message|safe %} 
  # Don't display anything
{% else %}
--- Your remaining code ---

Upvotes: 1

Related Questions