Django:内置密码重置视图

时间:2022-11-15 09:57:44

I am following the documentation and I am getting a NoReverseMatch error when I click on the page to restart my password.

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

NoReverseMatch at /resetpassword/ Reverse for 'password_reset_done' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

NoReverseMatch at / resetpassword /反向'password_reset_done',参数'()'和关键字参数'{}'未找到。尝试过0种模式:[]

urls.py:

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'),

Here is the code that calls this url in my base.html template:

以下是在我的base.html模板中调用此网址的代码:

<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!

我一直在这工作几个小时。 (我是初学者!)非常感谢任何帮助,谢谢!

1 个解决方案

#1


11  

Add the url name to the entry in your urls.py for password_reset_done:

将url名称添加到urls.py中用于password_reset_done的条目:

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

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.

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

https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse for the details on reverse.

https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse获取有关反向的详细信息。

#1


11  

Add the url name to the entry in your urls.py for password_reset_done:

将url名称添加到urls.py中用于password_reset_done的条目:

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

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.

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

https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse for the details on reverse.

https://docs.djangoproject.com/en/dev/ref/urlresolvers/#django.core.urlresolvers.reverse获取有关反向的详细信息。