Python 如果django中的重置密码电子邮件链接错误,则未找到页面(404)错误

Python 如果django中的重置密码电子邮件链接错误,则未找到页面(404)错误,python,django,forgot-password,Python,Django,Forgot Password,我正在使用django默认密码重置功能。我通过电子邮件获得设置新密码的电子邮件链接 如果url是正确的,那么就可以了。如果我放了一个错误或无效的链接 The current URL, account/reset/NTQ/4ox-7f135b9b74e7a4aa909fdd/, didn't match any of these. accounts/url.py-- 但在这种情况下,我在/account/reset/NTQ/4ox-7f135b9b74e7a4aa909fdd/处得到了断言错误

我正在使用django默认密码重置功能。我通过电子邮件获得设置新密码的电子邮件链接

如果url是正确的,那么就可以了。如果我放了一个错误或无效的链接

The current URL, account/reset/NTQ/4ox-7f135b9b74e7a4aa909fdd/, didn't match any of these.
accounts/url.py--

但在这种情况下,我在/account/reset/NTQ/4ox-7f135b9b74e7a4aa909fdd/处得到了断言错误


非常感谢您的帮助。

您必须修改url的正则表达式,使其适用于所有url

url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,23})/$',
    auth_views.password_reset_confirm, name='password_reset_confirm'),
url(r'^reset/(?P[0-9A-Za-z_ \-])/(?P[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,23})/$,
auth_views.password_reset_confirm,name='password_reset_confirm'),
对于您提到的示例链接,上面的链接将起作用。您可以按照相同的方式修改正则表达式,以便根据您的需求处理更多情况


当您的url指向带有错误标记的链接时,它将抛出错误,从而显示模板的其他部分。

您已经描述了当前的预期行为。但是你想要什么呢?如果url是错误的,它不应该显示404错误。相反,它应该显示
password\u reset\u confirm.html
file.html的
else
部分。成功了。但是我不知道为什么它是{1,20}而不是{1,23}。这是我能看到的唯一变化。他们必须将其设置为仅此而已。你可以随意修改。你能再解释一下吗?我不明白这是怎么回事。你说have可以根据你的喜好进行修改,但是我怎么知道需要什么样的修改才能与模式匹配呢。
{% extends 'base.html' %}

{% block content %}
  {% if validlink %}
    <h3>Change password</h3>
    <form method="post">
      {% csrf_token %}
      {{ form.as_p }}
      <button type="submit">Change password</button>
    </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 %}
url(r'^reset/',auth_views.password_reset_confirm, name='empty_password_reset_confirm')
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,23})/$',
    auth_views.password_reset_confirm, name='password_reset_confirm'),