I would not recommend checking in the settings whether the user arrived by changing the password. I think that ideally the whole logic of password changes is contained in the same place. This makes it easier to find the logic and does not require the settings view to be aware of viewing the password change (so you can easily change the logic to redirect the user to another location).
It's best to write your own look based on PasswordChangeForm instead of using the built-in password_change view. With this approach, you can use the message structure to display a successful message. (You also need to enable the message framework and put its markup in your views.)
For example, if you want to display a simple message and redirect back to a URL template called 'settings' , you can write a representation like this:
from django.contrib import messages from django.contrib.auth.forms import PasswordChangeForm from django.core.urlresolvers import reverse_lazy from django.views.generic import FormView class PasswordChangeView(FormView): template_name = 'registration/password_change_form.html' form_class = PasswordChangeForm success_url = reverse_lazy('settings') def get_form_kwargs(self): kwargs = super(PasswordChangeView, self).get_form_kwargs() kwargs['user'] = self.request.user return kwargs def form_valid(self, form): form.save() messages.success(self.request, "Your password has been changed.") return super(FormView, self).form_valid(form)
We hope that the password_change representation will be made based on the class in the future, allowing the same behavior with even fewer templates.
source share