NoReverseMatch at /auth/password/reset/

195 Views Asked by At

I am using dj-rest-auth package to do auth related functions, installed the package and added to installed apps and included it in main url as follows

path('auth/', include('dj_rest_auth.urls')),

it works for login, logout etc, but when I do password reset it throws the error

http://127.0.0.1:8000/auth/password/reset/

Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name

NoReverseMatch at /auth/password/reset/
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Request Method: POST
Request URL:    http://127.0.0.1:8000/auth/password/reset/
Django Version: 3.2
Exception Type: NoReverseMatch
Exception Value:    
Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name.
Exception Location: /home/biju/Desktop/reporting-system/lib/python3.8/site-packages/django/urls/resolvers.py, line 694, in _reverse_with_prefix
Python Executable:  /home/biju/Desktop/reporting-system/bin/python
Python Version: 3.8.10
Python Path:    
['/home/biju/Desktop/reporting-system',
 '/usr/lib/python38.zip',
 '/usr/lib/python3.8',
 '/usr/lib/python3.8/lib-dynload',
 '/home/biju/Desktop/reporting-system/lib/python3.8/site-packages']
Server time:    Fri, 01 Apr 2022 16:01:18 +0000
1

There are 1 best solutions below

3
Razenstein On

the urlpattern in https://github.com/iMerica/dj-rest-auth/blob/master/dj_rest_auth/urls.py:

...
 path('password/reset/confirm/', PasswordResetConfirmView.as_view(), name='rest_password_reset_confirm'), 
...

so you need to change 'password_reset_confirm' to 'rest_password_reset_confirm' in your html url tag or in django function call like reverse()

update:

see https://dj-rest-auth.readthedocs.io/en/latest/faq.html

"You need to add password_reset_confirm url into your urls.py (at the top of any other included urls). Please check the urls.py module inside demo app example for more details."

the package expects something like:

path('password/reset/confirm/<uidb64>/<token>',TemplateView.as_view(template_name="password_reset_confirm.html"),
        name='password_reset_confirm'),
path('auth/', include('dj_rest_auth.urls')),

see the demo urls.py: https://github.com/iMerica/dj-rest-auth/blob/24678437b3cdf3fa663880ab66a42aa0992b1d39/demo/demo/urls.py

strange for me that it is mentioned only in the FAQ - looks to me like a bug in the confirm email generation where they use the wrong urlpattern name without the "rest" prefix .