Password Reset Email — Django101

pertama-tama import auth di urls.py

from django.urls import path

from django.contrib.auth import views as auth_views

from . import views

urlpatterns = [
path('register/', views.registerPage, name="register"),
path('login/', views.loginPage, name="login"),
path('logout/', views.logoutUser, name="logout"),

path('', views.home, name="home"),
path('user/', views.userPage, name="user-page"),

path('account/', views.accountSettings, name="account"),

path('products/', views.products, name='products'),
path('customer/<str:pk_test>/', views.customer, name="customer"),

path('create_order/<str:pk>/', views.createOrder, name="create_order"),
path('update_order/<str:pk>/', views.updateOrder, name="update_order"),
path('delete_order/<str:pk>/', views.deleteOrder, name="delete_order"),

path('reset_password/',
auth_views.PasswordResetView.as_view(template_name="accounts/password_reset.html"),
name="reset_password"),

path('reset_password_sent/',
auth_views.PasswordResetDoneView.as_view(template_name="accounts/password_reset_sent.html"),
name="password_reset_done"),

path('reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(template_name="accounts/password_reset_form.html"),
name="password_reset_confirm"),

path('reset_password_complete/',
auth_views.PasswordResetCompleteView.as_view(template_name="accounts/password_reset_done.html"),
name="password_reset_complete"),


]

password_reset.html

<h3>Password reset</h3>

<p>Forgotten your password? Enter your email address below, and we’ll email instructions for setting a new one.</p>

<form method="post">

{% csrf_token %}
{{form}}
<input type="Submit" name="Send email">

</form>

password_reset_send.html

<h3>Password reset sent</h3>


<p>We’ve emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly.</p>

<p>If you don’t receive an email, please make sure you’ve entered the address you registered with, and check your spam folder.</p>

password_reset_form

<h3>Enter new password</h3>

<p>Please enter your new password twice so we can verify you typed it in correctly.</p>

<form method="post">

{% csrf_token %}
{{form}}
<input type="Submit" name="Update Password">

</form>

password_reset_done

<h3>Password reset complete</h3>

<p>Your password has been set. You may go ahead and log in now.</p>

<a href="/">Log in</a>

Konfigurasi SMTP

#SMTP Configuration

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''

aktifkan less security akun gmail.com

https://myaccount.google.com/lesssecureapps