0
0
Djangoframework~30 mins

Password change and reset in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Password change and reset
📖 Scenario: You are building a simple Django web app where users can change their password or reset it if forgotten. This is common in real websites to keep accounts secure.
🎯 Goal: Create the basic setup for password change and reset using Django's built-in views and URLs.
📋 What You'll Learn
Create a Django project and app
Set up URL patterns for password change and reset
Use Django's built-in authentication views
Create simple templates for password change and reset forms
💡 Why This Matters
🌍 Real World
Most websites need a way for users to change or reset their passwords securely. Django provides built-in views to handle this safely and easily.
💼 Career
Knowing how to implement password management is essential for web developers working with Django to build secure user authentication systems.
Progress0 / 4 steps
1
Create URL patterns for password change and reset
In your Django app's urls.py, import path and auth_views from django.contrib.auth. Then create a list called urlpatterns with these exact paths: password_change/ using auth_views.PasswordChangeView.as_view() named password_change, and password_reset/ using auth_views.PasswordResetView.as_view() named password_reset.
Django
Need a hint?

Use path to add URLs and auth_views.PasswordChangeView.as_view() for the password change view.

2
Add success URLs for password change and reset
In the same urls.py, add two more paths to urlpatterns: password_change/done/ using auth_views.PasswordChangeDoneView.as_view() named password_change_done, and password_reset/done/ using auth_views.PasswordResetDoneView.as_view() named password_reset_done.
Django
Need a hint?

Use auth_views.PasswordChangeDoneView.as_view() and auth_views.PasswordResetDoneView.as_view() for success pages.

3
Add URLs for password reset confirm and complete
Extend urlpatterns by adding these two paths: reset/// using auth_views.PasswordResetConfirmView.as_view() named password_reset_confirm, and reset/done/ using auth_views.PasswordResetCompleteView.as_view() named password_reset_complete.
Django
Need a hint?

Use URL parameters <uidb64> and <token> for the reset confirm URL.

4
Create simple templates for password change and reset forms
Create two HTML files in your templates folder: registration/password_change_form.html and registration/password_reset_form.html. Each should have a <form> with method post and a submit button with text Change Password and Reset Password respectively. Include the CSRF token inside each form.
Django
Need a hint?

Use Django template tags for CSRF token and render the form fields with {{ form.as_p }}.