6

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

andrea56
  • 397
  • 3
  • 21

2 Answers2

11

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": ""
}
andrea56
  • 397
  • 3
  • 21
1
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'),
]
Pradip Kachhadiya
  • 2,067
  • 10
  • 28