Django password_change() View

Django provides the following two views functions which help us to change passwords.

View Function Description
password_change() It displays a password change form, which allows the user to change their password by retyping the existing password.
password_change_done() It displays a success message when a user successfully updates the password.

Both of these views are password protected using login_required decorator. So, if you try to access these views without logging in, Django will redirect you to the URL specified in LOGIN_URL setting, which in our case happens to be /cadmin/login/. If we had not set LOGIN_URL to 'login' then login_required would have redirected us to default login URL which is /accounts/login/. We can verify this by adding the following URL pattern at the beginning of the urlpatterns list in cadmin’s


If you are already logged in, logout first and then, visit, you will be redirected to

Notice that the redirected URL contains next query parameter whose value is /cadmin/password-change/. It means that after successful login the django.contrib.auth.login() view function will redirect the user to /cadmin/password-change/.

The password_change() view works in conjunction with password_change_done() view. The job of the password_change_done() view is to display the success message when user successfully updates password. The password_change() view accepts an additional argument named post_change_redirect. The post_change_redirect points to the URL to redirect after successful password change. Generally, it points to the URL pattern which calls password_change_done() view.

Open cadmin’s and add another URL pattern named password_change_done and update password_change URL pattern as follows:


To view the fruits of our labor visit If you are not already logged in, login now and you will be presented with password change page, which looks like this:

To change the password, enter your old password then your new password twice and hit “CHANGE MY PASSWORD” button at the bottom of the screen. On success you will be redirected to, which looks like this:

By default, password_change() and password_change_done() uses password_change_form.html and password_change_done.html templates respectively from Django Admin app (django.contrib.admin). We can override this behavior by using template_name keyword argument as usual.

Update password_change and password_change_done URL patterns as follows:


Create two new templates password_change.html and password_change_done.html in the cadmin app with the following code.



Visit the and you should see our custom password change template instead of the default one.

Update the password of the logged in user and on success you will get a page like this:

Note: To checkout this version of the repository type git checkout 31a.

Leave a Comment

%d bloggers like this: