Django: built-in password reset views(Django:内置密码重置视图)
问题描述
我正在关注文档,当我单击该页面以重新启动密码时收到 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:内置密码重置视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Django:内置密码重置视图


基础教程推荐
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 筛选NumPy数组 2022-01-01