NoReverseMatch at /user/password_reset/ Reverse for 'password_reset_done' not found

浪尽此生 提交于 2019-12-13 17:59:41

问题


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

'user' is an app name.

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:

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

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.


回答1:


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

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 Docs




回答2:


In your user/urls.py, it seems that you have no url, named /user/password_reset/

if you want to use django.auth default password reset then use,

from django.contrib.auth.views import password_reset

urlpatterns = patterns('',
     (r'^/accounts/password/reset/$', password_reset,{'template_name': 'my_templates/password_reset.html'}, name='password_reset_done'),
     ...
)

Here you can change your template name.



来源:https://stackoverflow.com/questions/45128577/noreversematch-at-user-password-reset-reverse-for-password-reset-done-not-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!