【问题标题】:Django: built-in password reset viewsDjango:内置密码重置视图
【发布时间】:2013-12-16 22:22:00
【问题描述】:

我正在关注文档,当我单击该页面以重新启动密码时收到 NoReverseMatch 错误。

NoReverseMatch 在 /resetpassword/ 未找到带有参数“()”和关键字参数“{}”的“password_reset_done”的反向操作。尝试了 0 个模式:[]

urls.py:

(r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done'),
(r'^resetpassword/$', 'django.contrib.auth.views.password_reset', name="reset_password"),
(r'^reset/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>,+)/$', 'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),

这是在我的 base.html 模板中调用此 url 的代码:

<a href="{% url 'reset_password' %}">Reset Password</a>

我已经为此工作了好几个小时。 (我是初学者!)任何帮助将不胜感激,谢谢!

【问题讨论】:

    标签: python django authentication passwords reset


    【解决方案1】:

    urls.py 中为password_reset_done 的条目添加网址名称:

    (r'^resetpassword/passwordsent/$', 'django.contrib.auth.views.password_reset_done', name='password_reset_done'),
    

    在内部,password_reset 视图使用reverse('password_reset_done') 在重置密码后查找将用户发送到何处。 reverse 可以采用函数名的字符串表示形式,但它需要与您的模式中使用的形式相匹配 - 在这种情况下,它无法匹配,因为在您的模式中指定了完整路径,但在反向调用中没有指定。您可以从模块中导入视图并在模式中仅使用它们的名称,或者在模式中使用前缀(如果您更喜欢 name 参数)。

    https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reversereverse 的详细信息。

    【讨论】:

      猜你喜欢
      • 2011-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多