PART-15

Making a Reset Password Request With Django

It’s now the time to add the reset password functionality. Without throwing all the URLs or imports or settings required, let me take you to step by step. We need a URL for a reset password, right?, So jump in the blog_project/urls.py and add the URL or link for the password reset, using the built-in PasswordResetView present in the auth view of django.contrib and specify the url and template name there.

...
path('password-reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'),
name='password_reset'),
<h1>Trouble Signing In?<br>
<span>request a password reset, and we will have you up again..</span>
</h1>
<form method='post'>
{%csrf_token%}
{{form}}
<input type="submit" value="forgotten password" class="submit-btn">
</form>

<small class="text-muted">
try signing in again? <a class="ml-2" href="{% url 'login' %}">Log Into Your Account</a>
</small>
...
path('password-reset-confirm/<uidb64>/<token>/', auth_views.PasswordResetConfirmView.as_view(template_name='users/pas sword_reset_confirm.html'),
name='password_reset_confirm'),
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_NAME')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')
...
path('password-reset-done/', auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'),
name='password_reset_done'),
<p>
An email has been sent you, please check your inbox and follow the instructions or the trash in case you didn’t find one.</p>
...
path('password-reset-complete/',
auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'),
name='password_reset_complete'),
<h1>Your password has been reset, you can <a href="{%url 'login'%}>login to your account now</a> </h1>

Posting Django Tutorials with Beginner to Advanced Projects