Django密码重置确认

3

我刚开始学Django,感到很困惑。

我正在使用内置的rest auth开发身份验证API。

我希望通过API视图重置密码,但是我发送的邮件链接将我重定向到“密码重置确认”HTML模板,但我需要将此链接重定向到API视图。

我期望重定向到这个页面:

enter image description here

但我的电子邮件链接将重定向到此HTML模板页面:

enter image description here

这个电子邮件是由password_reset_email.html发送的。

someone asked for password reset for email {{ email }}. Follow the link below:
{{protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %}

这是重定向电子邮件链接的URL地址:
path('password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)/(?P<token>.+)/$', auth_views.PasswordResetConfirmView, name='password_reset_confirm'),
1个回答

0

这是你的网址:

path('password/reset/confirm/(?P<uidb64>[0-9A-Za-z]+)/(?P<token>.+)/$', auth_views.PasswordResetConfirmView, name='password_reset_confirm'),

你没有指定你的模板文件。这就是为什么它会采用Django默认模板并显示Django管理员密码重置页面。

更新你的URL。并指定你的自定义模板名称。

urls.py

path('password-reset-confirm/<uidb64>/<token>',auth_views.PasswordResetConfirmView.as_view(template_name='users/password_reset_confirm.html'), name='password_reset_confirm'),

这是我的自定义模板。请从Django rest framework文档中更新您的模板。

password_reset_confirm.html

{% extends "users/users_base.html" %}
{% load crispy_forms_tags %}
{% load static %}

{% block content %}
<!-- Nested Row within Card Body -->

    <form class="user" method="POST">
        {% csrf_token %}
        <div class="form-group mb-6">
             {{ form | crispy }}
        </div>
        <div class="form-group text-center ">
            <button type="submit" class="btn btn-primary btn-user text-center">
                Change Password
            </button>
        </div>
    </form>

{% endblock %}

我的表单没有显示出来,只有按钮显示。当我使用 {{form}} 时,我得到了 none。 - blockhead

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接