我正在关注文档,当我单击该页面以重新启动密码时收到 NoReverseMatch 错误.
I am following the documentation and I am getting a NoReverseMatch error when I click on the page to restart my password.
NoReverseMatch 在/resetpassword/未找到带有参数()"和关键字参数{}"的password_reset_done"的反向操作.尝试了 0 个模式:[]
NoReverseMatch at /resetpassword/ Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
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 的代码:
Here is the code that calls this url in my base.html template:
<a href="{% url 'reset_password' %}">Reset Password</a>
我已经为此工作了好几个小时.(我是初学者!)任何帮助将不胜感激,谢谢!
I have been working at this for hours. (I'm a beginner!) Any help would be much appreciated, thanks!
在 urls.py
中为 password_reset_done
的条目添加 url 名称:
Add the url name to the entry in your urls.py
for 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
参数).
Internally, the password_reset
view uses reverse('password_reset_done')
to look up where to send the user after resetting the password. reverse
can take a string representation of a function name, but it needs to match the form used in your patterns - in this case, it can't match because the full path is specified in your pattern but not in the reverse call. You could import the views from the module and use just their names in the pattern or use a prefix in your patterns if you'd prefer that over the name
argument.
https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse 了解 reverse
的详细信息.
https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse for the details on reverse
.
这篇关于Django:内置密码重置视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!