I'm trying to add password reset function to my project and get an error RelatedObjectDoesNotExist. But after following the link from the letter I'm redirected to http://127.0.0.1:8000/password_reset_confirm/Mw/set-password/ and there I can see password_reset_confirm picture. So аfter filling in the fields and clicking on the button I get an error.

Here is the screenshot of the error error picture

I don't know where I shound search.

Here is my settings.py file

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'jahhmcmltpqwigik'

And the main urls.py

path('password_reset/', 
        auth_views.PasswordResetView.as_view(template_name='users/password_reset.html'), 
        name='password_reset'),
    path('password_reset_confirm/<uidb64>/<token>/', 
        auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), 
        name='password_reset_confirm'),
    path('password_reset/done/', 
        auth_views.PasswordResetDoneView.as_view(template_name='users/password_reset_done.html'), 
        name='password_reset_done'),
    path('password_reset_complete/', 
        auth_views.PasswordResetCompleteView.as_view(template_name='users/password_reset_complete.html'), 
        name='password_reset_complete'),

password_reset.html

{% extends 'blog/base.html' %}
{% load crispy_forms_tags %}
{% block main_section %}
    <div class="form-section">
        <h2>Восстановление пароля</h2>
        <form method="POST">
            {% csrf_token %}
            {{ form|crispy }}
            <button type="submit" class="btn btn-danger">Запросить новый пароль</button>
        </form>
    </div>
{% endblock main_section %}

password_reset_done.html

{% extends 'blog/base.html' %}
{% block main_section %}
    <div class="form-section">
        <h2>Вы успешно вышли обновили пароль</h2>
        Ваш пароль был отправлен на почту.
    </div>
{% endblock main_section %}

password_reset_confirm.html

{% extends 'blog/base.html' %}
{% load crispy_forms_tags %}
{% block main_section %}
    <div class="form-section">
        <h2>Восстановление пароля</h2>
        <form method="POST">
            {% csrf_token %}
            {{ form|crispy }}
            <button type="submit" class="btn btn-danger">Установить пароль</button>
        </form>
    </div>
{% endblock main_section %}

password_reset_complete

{% extends 'blog/base.html' %}
{% block main_section %}
    <div class="form-section">
        <h2>Вы успешно вышли обновили пароль</h2>
        Ваш пароль был изменен!
    </div>
{% endblock main_section %}

0 Answers