Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 500
andrea56 Avatar asked Oct 31 '18 16:10

andrea56


People also ask

How to reset user's password if they forget it in Django?

In addition to login and logout views, django's auth app has views that can let users reset their password if they forget it. Let's go ahead and see how we can add this functionality into our app. 1) User clicks on "forgot password" link - This will take them to a page where they will be prompted to enter their email address.

Is'password_reset_confirm'a valid view name?

Reverse for 'password_reset_confirm' not found. 'password_reset_confirm' is not a valid view function or pattern name. Is it because my app name is houses?

What is Django_rest_passwordreset_no_information_leakage?

DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE - will cause a 200 to be returned on POST $ {API_URL}/reset_password/ even if the user doesn't exist in the databse (Default: False) DJANGO_REST_MULTITOKENAUTH_REQUIRE_USABLE_PASSWORD - allows password reset for a user that does not have a usable password (Default: True)

Is this library compatible with Django REST framework (DRF)?

This library should be compatible with the latest Django and Django Rest Framework Versions. For reference, here is a matrix showing the guaranteed and tested compatibility. This package supports the DRF auto-generated documentation (via coreapi) as well as the DRF browsable API.


1 Answers

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": ""
}
like image 166
andrea56 Avatar answered Sep 21 '22 16:09

andrea56