django password_reset不起作用

时间:2019-05-05 13:07:42

标签: django

我正在尝试将密码重置功能添加到我的项目中,并出现错误RelatedObjectDoesNotExist。但是,按照字母中的链接操作后,我被重定向到here,在那里我可以看到http://127.0.0.1:8000/password_reset_confirm/Mw/set-password/。因此,在填写字段并单击按钮后,我得到一个错误。

这是错误的屏幕截图 password_reset_confirm picture

我不知道该在哪里搜索

这是我的settings.py文件

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

还有主要的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 个答案:

没有答案