Question

I'm trying to create an account settings page for logged-in users. One of the things users should be able to do is to change their password.

I'm using django-registration and it provides a password change form at site/accounts/password/change by default, and it works. However, I want this function to be available at an Account Settings page instead, along with other administrative functions.

I first tried copying the template code, but it did not work because it includes a special form to create the inputs for the passwords (to handle validation). I don't know how to include this form in my own template.

How can I recreate these forms in my own Account Settings template?

This is the default password change template. I want to reuse form.oldpassword and the others in a separate template.

Was it helpful?

Solution

Django-registration doesn't implement its own password change view, it reuses the one included in Django (django.contrib.auth.views.password_change). It is hooked in through registration.auth_urls which is included in the default and simple registration backends.

By default the view uses django.contrib.auth.forms.PasswordChangeForm (which can be overridden through the password_change_form parameter).

When you only reuse the form (which you can do of course, just import the above form in your custom view), you should be aware that you would still be missing the whole view logic. So unless you have a more complex view in mind, you should consider to reuse it and just override the registration/password_change_form.html and registration/password_change_done.html templates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top