Search code examples
pythondjangodjango-rest-frameworkdjango-rest-auth

django-rest-auth urls not found


I'm trying to implement django-rest-auth, but the url is not recognized and throw 404 error. The 'rest_auth' is added in the INSTALLED_APPS and path also included in the urls.py file.

Request URL:    http://127.0.0.1:8000/api/v1/rest-auth/login/
Using the URLconf defined in blog_project.urls, Django tried these URL patterns, in this order:

admin/
api/v1/ <int:pk>/
api/v1/
api-auth/
api/v1/rest-auth ^password/reset/$ [name='rest_password_reset']
api/v1/rest-auth ^password/reset/confirm/$ [name='rest_password_reset_confirm']
api/v1/rest-auth ^login/$ [name='rest_login']
api/v1/rest-auth ^logout/$ [name='rest_logout']
api/v1/rest-auth ^user/$ [name='rest_user_details']
api/v1/rest-auth ^password/change/$ [name='rest_password_change']
The current path, api/v1/rest-auth/login/, didn't match any of these.

settings.py content

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # 3rd Party
    'rest_framework',
    'rest_framework.authtoken',
    'rest_auth',

    # Apps
    'posts.apps.PostsConfig',
]

Below is the content of my urls.py

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/v1/', include('posts.urls')),
    path('api-auth/', include('rest_framework.urls')),
    path('api/v1/rest-auth', include('rest_auth.urls')),
]

I'm not able to figure out, what is wrong with the code.


Solution

  • Your problem is here.

    path('api/v1/rest-auth', include('rest_auth.urls')),
    

    You need to add a / at the end of your URL string like this -

    path('api/v1/rest-auth/', include('rest_auth.urls')),