django密码更改完成失败

django密码更改完成失败,django,authentication,change-password,Django,Authentication,Change Password,我几乎已经实现了密码重置过程,但当我验证密码更改时,我不会在重置完成模板上结束,并得到模板上显示: 密码重置链接无效 但是,密码已更改,可以使用新密码登录。看起来重定向是错误的,但我不明白为什么 这是我的URL.py: path('reset/<uidb64>/<token>', auth_views.PasswordResetConfirmView.as_view( template_name='news/user/password_reset_confirm.

我几乎已经实现了密码重置过程,但当我验证密码更改时,我不会在重置完成模板上结束,并得到模板上显示:

密码重置链接无效

但是,密码已更改,可以使用新密码登录。看起来重定向是错误的,但我不明白为什么

这是我的URL.py:

path('reset/<uidb64>/<token>', auth_views.PasswordResetConfirmView.as_view(
    template_name='news/user/password_reset_confirm.html',
    success_url='../password-change/done'), name='password_reset_confirm'),
path('password-change/done', auth_views.PasswordResetCompleteView.as_view(template_name='news/user/password_reset_complete.html'), name='password_change_done'),
path('reset/',auth_views.PasswordResetConfirmView.as_view(
模板\u name='news/user/password\u reset\u confirm.html',
成功\u url='../password change/done'),name='password\u reset\u confirm'),
路径('password-change/done',auth_views.PasswordResetCompleteView.as_view(template\u name='news/user/password\u reset\u complete.html'),name='password\u change\u done',
这是我的模板:

{% block content %}

{% if validlink %}

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

<form method="post">{% csrf_token %}
<fieldset class="module aligned">
    <div class="form-row field-password1">
        {{ form.new_password1.errors }}
        <label for="id_new_password1">New password:</label>
        {{ form.new_password1 }}
    </div>
    <div class="form-row field-password2">
        {{ form.new_password2.errors }}
        <label for="id_new_password2">Confirm password:</label>
        {{ form.new_password2 }}
    </div>
    <input type="submit" value="Change my password">
</fieldset>
</form>

{% else %}

<p>The password reset link was invalid, possibly because it has already been used.  Please request a new password reset.</p>

{% endif %}

{% endblock %}
{%block content%}
{%if validlink%}
请输入两次新密码,以便我们验证您键入的密码是否正确

{%csrf_令牌%} {{form.new_password1.errors} 新密码: {{form.new_password1}} {{form.new_password2.errors} 确认密码: {{form.new_password2}} {%else%} 密码重置链接无效,可能是因为它已被使用。请请求重新设置新密码

{%endif%} {%endblock%}
您在
密码重置确认路径上缺少最后一个斜杠,这会导致您的帖子转到错误的位置。应该是:

path('reset/<uidb64>/<token>/', ...
path('reset//'。。。

请注意,您的
成功\u url
也可能是错误的,我怀疑
将按您认为的方式工作。

嘿,非常感谢Daniel。我已经成功地使它工作了,但不得不将我的url更改为这么长的url,这正常吗?
路径('reset/Mg/set password/password change/done',auth\u views.PasswordResetCompleteView.as\u view(模板“\u name='news/user/password\u reset\u complete.html”)、name='password\u change\u done')
success\u url='../password change/done'
是错误的,url不应该包含类似操作系统的路径(
)。这可能就是用户被重定向到这个奇怪url的原因。