Django:内置密码重置视图

Django: built-in password reset views(Django:内置密码重置视图)
本文介绍了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:内置密码重置视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Leetcode 234: Palindrome LinkedList(Leetcode 234:回文链接列表)
How do I read an Excel file directly from Dropbox#39;s API using pandas.read_excel()?(如何使用PANDAS.READ_EXCEL()直接从Dropbox的API读取Excel文件?)
subprocess.Popen tries to write to nonexistent pipe(子进程。打开尝试写入不存在的管道)
I want to realize Popen-code from Windows to Linux:(我想实现从Windows到Linux的POpen-code:)
Reading stdout from a subprocess in real time(实时读取子进程中的标准输出)
How to call type safely on a random file in Python?(如何在Python中安全地调用随机文件上的类型?)