从 Django 类继承的密码重置功能 - 反向 url 问题('uidb64')

问题描述 投票:0回答:1

我想创建密码重置功能但更改模板。
所以我继承了 Django 类。

插入电子邮件重置密码后,出现以下错误:

/accounts/password-reset/ 处无反向匹配

使用关键字参数反转“confirm_reset_password” '{'uidb64': '', 'token': '4y5-9ae986836e35f95b842c'}' 未找到。 1 尝试过的模式: ['账户\/密码重置确认/(?P[0-9A-Za-z_\-]+)/(?P[0-9A-Za-z]{1,13}-[0-9A -Za-z]{1,20})/$']

我认为问题在于“uidb64”,但我不知道为什么是空的。

浏览量:

class CustomPasswordResetView(PasswordResetView):

    form_class = CustomPasswordResetForm
    email_template_name = 'account/password_reset_email.html'
    template_name = 'account/password_reset.html'

class UserPasswordResetConfirmView(PasswordResetConfirmView):

    pass

形式:

class CustomPasswordResetForm(PasswordResetForm):

    email = forms.EmailField(widget=TextInputWidget)

网址:

path('password-reset/', UserPasswordResetView.as_view(), name='reset_password'),

re_path(r'^password-reset-confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
UserPasswordResetConfirmView.as_view(), name='confirm_reset_password')

在重置模板中:

<form action="" method="post">
  {% csrf_token %}
  <div class="row ">
    {{ form.email }}
  </div>
  <div class="l-action">
    <input type="submit" class="button" value="Reset my password">
  </div>
</form>

在电子邮件模板中:

a href="http://{{ domain }}{% url 'users:confirm_reset_password' uidb64=uidb token=token %}"
django django-views django-authentication
1个回答
2
投票

我认为您的电子邮件模板包含错误。你写:

a href="http://{{ domain }}{% url 'users:confirm_reset_password' uidb64=uidb token=token %}"

但是,根据

文档
[Django-doc]uidb64参数应该将
uid
变量作为参数,所以:

a href="http://{{ domain }}{% url 'users:confirm_reset_password' uidb64=uid token=token %}"
© www.soinside.com 2019 - 2024. All rights reserved.