How to Change the Page Transition Destination When You Change Password with django-allauth

Asked 2 years ago, Updated 2 years ago, 110 views

How do I change the page transition destination when I change the password with django-allauth?
Now, if the change succeeds, nothing happens, and if it fails, it seems to be 404.

django 3.1.1
django-allauth 0.42.0

python django

2022-09-30 19:27

1 Answers

The configuration of the official document (settings.py) contains everything you can set on https://django-allauth.readthedocs.io/en/latest/configuration.html, for example, the ACCOUNT_LOGOUT_REDIRECT_URL, but it didn't seem to have the desired settings (just look).

Then...

defined in venv\Lib\site-packages\allauth\account\views.py
class PasswordChangeView (AjaxCapableProcessFormViewMixin, FormView):
    template_name = "account/password_change." + app_settings.TEMPLATE_EXTENSION
    form_class = ChangePasswordForm
    success_url = reverse_lazy("account_change_password")

If you create a class that inherits this PasswordChangeView and overwrite success_url, you can do it. (Note:) Overwrite the following routing to accounts\urls.py as well

 path("password/change/", views. Your view function, name="account_change_password"),

Incidentally, if you look at the default behavior, when the password change was successful, the same form was displayed in GET and the flash message "Password changed" was displayed (this action is described in the form_valid method of the class above).
Also, if you failed, for example, if you entered the wrong current password, the form error message "Please enter your current password" appeared on the form.404 is strange.Please try to find the relevant corrections.I'm sorry that this is not a complete answer.


2022-09-30 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.