Password_reset_done error when attempting to creat

2019-09-18 23:53发布

I want to allow the user to reset password when the user is signed out and cannot remember the password.

I am using the django authentication framework and have created the reset_password and password_reset_done mappers.

Issue : Though I have created the password_reset_done function I continue to get the below error. Is there a step that I missed that is causing this error? I do not know what I have done wrong.

I have posted all the code that I think is relevant to what I attempting to do.

Edit with full TraceBack:

enter image description here

Here is the code :

relative urls.py

from django.conf.urls import url
from . import views

from django.contrib.auth.views import login, logout, password_reset, password_reset_done


urlpatterns = [
        url(r'^$', views.vedic_view, name = 'vedic_home_view'),
        url(r'^login/$', login, {'template_name' : 'exist/login.html'}, name = 'login'),
        url(r'^logout/$', logout, {'template_name' : 'exist/logout.html'}, name = 'logout'),
        url(r'^register/$', views.register_view, name = 'register'),
        url(r'^profile/$', views.view_profile, name = 'view_profile'),
        url(r'^profile/edit/$', views.edit_profile, name = 'edit_profile'),
        url(r'^change-password/$', views.change_password, name = 'change_password'),


        url(r'^reset-password/$', password_reset, name = 'reset_password'),
        url(r'^reset-password/done/$', password_reset_done, name = 'password_reset_done')
]

main urls.py

from django.conf.urls import url
from django.contrib import admin


from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^admin/', admin.site.urls),
] +  static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)


from django.conf.urls import include
from django.views.generic import RedirectView


urlpatterns += [
    url(r'^exist/', include('exist.urls', namespace = 'exist')),
        url(r'^$', RedirectView.as_view(url='/exist/', permanent=True)),
]

3条回答
在下西门庆
2楼-- · 2019-09-19 00:41

As I see, you didn't include relative.url in your main urls.

EDIT

in relative urls

app_name='exists' #with this name you can call in main urls
urlpatterns = [
        url(r'^$', views.vedic_view, name = 'vedic_home_view'),
        #...

In main url:

urlpatterns = [
    url(r'^exists/', include('exists.urls')),
    #...

EDIT 2

Here'sthe docs on the subject, it explains it better than me with examples.

查看更多
贪生不怕死
3楼-- · 2019-09-19 00:43

password_reset_done is within the exists namespace. It looks like you are trying to reverse the named URL without including the namespace argument somewhere. We would need to see your full traceback to see exactly where that is happening.

Since you are using the built-in auth views, the easiest fix would probably be to move your password reset handling up to your main urls.py. Notice in your traceback that the built-in password_reset view does this:

post_reset_redirect = reverse('password_reset_done')

The default implementation here is to reverse to password_reset_done without any namespace. Moving the relevant URLs up to your main urls.py will allow them to be accessed via reverse without a namespace argument, making the built-in views happy.

查看更多
来,给爷笑一个
4楼-- · 2019-09-19 00:47

I realize what the issue is.

For the built-in reset view there is a post_reset_redirect variable that uses the default implementation reverse(password_reset_done) to go to the password_reset_done view.

The issue is that in my main urls.py document I created the namespace variable

namespace = exist

However I did not override the default post_reset_redirect implementation from reverse(password_reset_done) to reverse(exist:password_reset_done).

So my current

url(r'^reset-password/$', password_reset, name = 'reset_password'),

should now look like

url(r'^reset-password/$', { 'post_reset_redirect': 'exist:password_reset_done'}, password_reset, name = 'reset_password')

查看更多
登录 后发表回答