Change Password with PasswordChangeView
A snippet for adding password change functionality to Django apps.
# urls.py
from django.urls import path
from django.contrib.auth.views import PasswordChangeView
from django.urls import reverse_lazy
urlpatterns = [
path('change-password/', PasswordChangeView.as_view(
template_name='change_password.html',
success_url=reverse_lazy('password_change_done')
), name='change_password'),
]
# templates/change_password.html
<h2>Change Password</h2>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Change Password</button>
</form>
Explanation:
-
PasswordChangeViewallows authenticated users to change their password securely. - It uses Django's built-in form and checks the current password before saving the new one.
-
A success URL is defined using
reverse_lazyto redirect after the password is updated. -
Customize the
change_password.htmltemplate to match your site's design.
- Category Authentication & Authorization
- Total Views 652
- Last Modified 25 December, 2025
- Tags #password change #auth #views #forms
Previous snippet
Password Reset with PasswordResetView
Next snippet