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:
  • PasswordChangeView allows 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_lazy to redirect after the password is updated.
  • Customize the change_password.html template to match your site's design.
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.