在/ user / password_reset /找不到与'password_reset_done'相反的NoReverseMatch [英] NoReverseMatch at /user/password_reset/ Reverse for 'password_reset_done' not found

查看:177
本文介绍了在/ user / password_reset /找不到与'password_reset_done'相反的NoReverseMatch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Django身份验证系统,但出现错误:
在此处输入图片描述

I'm trying to use the Django authentication system, but I'm getting the error: enter image description here

用户是应用名称。

项目的urls.py:

Project's urls.py:

from django.conf.urls import url, include
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
     url(r'^admin/', admin.site.urls),
     ...
     url(r'^user/', include('user.urls', namespace='user')),
     ...
]

user / urls.py:

user/urls.py:

from django.conf.urls import url, include

from . import views


urlpatterns = [
    url(r'^register/$', views.register, name='register'),
    url(r'^settings/$', views.settings, name='settings'),
    url(r'^settings/password/$', views.password, name='password'),
    url(r'^settings/accounts/$', views.configure_accounts,
        name='configure_accounts'),
    url(r'^settings/accounts/error/$', views.configure_accounts_error,
        name='configure_accounts_error'),
    url('^', include('django.contrib.auth.urls')),
]

我可以访问/ user / login /,/ user / logout /。当我转到/ user / password_reset /时,我可以输入电子邮件,并且在按提交按钮后,发生错误(如图所示):

I can access /user/login/, /user/logout/. When I go to /user/password_reset/, I can enter email, and, after pressing 'Submit' button, an error occurs (shown at picture):

NoReverseMatch at /user/password_reset/
Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name.

任何想法如何解决?
非常感谢。

Any ideas how to fix this? Thanks a lot.

推荐答案

url(r'^password_reset/$', auth_views.password_reset, {
        'post_reset_redirect': '/user/password_reset/done/'
    }, name='password_reset'),
    url(r'^password_reset/done/$', auth_views.password_reset_done,
        name='password_reset_done'),
    url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        auth_views.password_reset_confirm, {
         'post_reset_redirect': '/user/reset/done/'
    }, name='password_reset_confirm'),
    url(r'^reset/done/$', auth_views.password_reset_complete,
        name='password_reset_complete'),

我在user / urls.py中设置了 post_reset_redirect ,一切开始正常运行。在重置页面上提交电子邮件后,控制台中什么也没显示,因为:

I set 'post_reset_redirect' in user/urls.py , and everything started to work properly. And after submitting email on reset page, nothing was displayed in console, because of this:


如果提供的电子邮件地址不存在,系统,该视图将不会发送电子邮件,但用户也不会收到任何错误消息。这样可以防止信息泄露给潜在的攻击者。

If the email address provided does not exist in the system, this view won’t send an email, but the user won’t receive any error message either. This prevents information leaking to potential attackers.

Django文档

这篇关于在/ user / password_reset /找不到与'password_reset_done'相反的NoReverseMatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆