DEV Community

Phansivang
Phansivang

Posted on

Django reset password and change password

urls.py in main project

from django.contrib import admin
from django.urls import path,include
from django.contrib.auth import views as user_views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('',include('users.urls')),
    path('',include('app.urls')),

    path('password-change/',user_views.PasswordChangeView.as_view(template_name='users/password_change.html'),name='password-change'),
    path('password-change-done/', user_views.PasswordChangeDoneView.as_view(template_name='users/password_change_done.html'),name='password_change_done'),
    path('password-reset/', user_views.PasswordResetView.as_view(template_name='users/password_reset.html'),name='password_reset'),
    path('password-reset-done/',user_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'),name='password_reset_done'),
    path('password-reset-confirm/<uidb64>/<token>/',user_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'),name='password_reset_confirm'),
    path('password-reset-complete/',user_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'),name='password_reset_complete')
]

Enter fullscreen mode Exit fullscreen mode

HTML you have to create in templates folder :

password_change.html
password_change_done.html
password_reset.html
password_reset_done.html
password_reset_confirm.html
password_reset_complete.html

settings.py

This setting for sending email to your client reset password

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = 'Email'
EMAIL_HOST_PASSWORD = 'Password'
Enter fullscreen mode Exit fullscreen mode

Top comments (0)