andrea56
andrea56

Reputation: 424

Django-rest-auth: Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name

I'm trying to use django-rest-auth password reset feature but after a post request at /rest-auth/password/reset/ i get the error stated in the title (Traceback) and i don't understand why. I followed the installation procedure from the documentation page. My urls.py is:

from django.urls import include, path

urlpatterns = [
    path('users/', include('users.urls')),
    path('rest-auth/', include('rest_auth.urls')),
    path('rest-auth/registration/', include('rest_auth.registration.urls')),

I also added the required apps in settings.py

Upvotes: 6

Views: 4524

Answers (2)

Pradip Kachhadiya
Pradip Kachhadiya

Reputation: 2235

from django.views.generic import TemplateView

urlpatterns += [
    path('rest-auth/', include('rest_auth.urls')),
    path('rest-auth/registration/', include('rest_auth.registration.urls')),

    url(r'^', include('django.contrib.auth.urls')),
    url(r'^rest-auth/password-reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
        TemplateView.as_view(template_name="password_reset_confirm.html"),
        name='password_reset_confirm'),
]

Upvotes: 1

andrea56
andrea56

Reputation: 424

I solved by adding

from django.urls import include, path, re_path
from rest_auth.views import PasswordResetConfirmView

re_path(r'^rest-auth/password/reset/confirm/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', PasswordResetConfirmView.as_view(),
            name='password_reset_confirm'),

to urlpatterns in urls.py . This way you will obtain a reset link in the mail like: ../password/reset/confirm/uid/token. In order to complete the procedure you must send a POST request to ../password/reset/confirm/ with this body:

{
    "new_password1": "",
    "new_password2": "",
    "uid": "",
    "token": ""
}

Upvotes: 11

Related Questions