NoReverseMatch at /accounts/password-reset/ for Password Reset in Django

Viewed 418

Error- In Django after submitting email in "password-reset" page, I am getting this error.

NoReverseMatch at /accounts/password-reset/ Reverse for 'password_reset_done' not found. 'password_reset_done' is not a valid view function or pattern name.


My Code in urls.py file-

urlpatterns = [
    url(r'^password-reset/',
        auth_views.PasswordResetView.as_view(
            template_name='accounts/password_reset.html'),
        name='password_reset'),

    url(r'^password-reset/done/',
        auth_views.PasswordResetDoneView.as_view(
            template_name='accounts/password_reset_done.html'),
        name='password_reset_done'),

    url(r'^password-reset-confirm/<uidb64>/<token>/',
        auth_views.PasswordResetConfirmView.as_view(
            template_name='accounts/password_reset_confirm.html'),
        name='password_reset_confirm'),
]

I also created separate HTML files for all pages in "accounts" directory. By the way, I am following this tutorial on youtube - click here

Url.py Code Screenshot

Error Screenshot

password_reset.html Screenshot

password_reset_done.html Screenshot

password_reset_confirm.html screenshot

Github: Click Here

2 Answers

How does the .html for url(r'^password-reset/done/',...) look like?

The issue is that you have included these views and templates inside of a separate django app called accounts. When you separate views and routes into a separate app, all of the route names that you specified will be namespaced.

URL namespaces allow you to uniquely reverse named URL patterns even if different applications use the same URL names. It’s a good practice for third-party apps to always use namespaced URLs (as we did in the tutorial). Similarly, it also allows you to reverse URLs if multiple instances of an application are deployed. In other words, since multiple instances of a single application will share named URLs, namespaces provide a way to tell these named URLs apart.

By default, the namespace assigned to those routes will be the application name (e.g., accounts) that you set in urls.py. This means that the fully qualified names for the views that you have specified are accounts:password_reset_done, etc. Thus, django cannot find the route / view that it is looking for which is the un-namespaced password_reset_done.

You can fix this by (1) moving your account login / password reset views to the Dipesh_Pal application and specifying the routes in Dipesh_Pal/urls.py, or (2) explicitly setting a namespace of '' when including the accounts.urls in Dipesh_Pal/urls.py.

Related