0

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?

user3595632
  • 5,380
  • 10
  • 55
  • 111
  • [use extra message tags](https://docs.djangoproject.com/en/1.10/ref/contrib/messages/#adding-extra-message-tags) – Wilfried Jan 21 '17 at 15:16
  • Why are you creating messages for your login/logout views if you're not showing them anywhere else? If you'd show them they wouldn't pop up the moment you access the `PasswordChangeView`. – Bono Jan 21 '17 at 16:30
  • @Bono oh cuz I used `django-allauth` and it shows messages automatically. – user3595632 Jan 22 '17 at 00:35

1 Answers1

1

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 ---
Brendan Metcalfe
  • 753
  • 10
  • 10