sunscrapers / djoser

REST implementation of Django authentication system.
MIT License
2.55k stars 458 forks source link

The current path, <code>auth/token/login/</code>, didn't match any of these. #477

Open AbdouTlili opened 4 years ago

AbdouTlili commented 4 years ago

hi guys i'm just getting started with djoser

after doing all steps ( installing, adding apps and config ..)

when i

curl -X POST http://localhost:8000/auth/users/ --data 'email=test&username=user1&password=StrongPass'

i get the right response

{"email": "test", "username": "user1", "id":1}

but when i try to login and get the token :

curl -X POST http://localhost:8000/auth/token/login/ --data 'username=user1&password=StrongPass'

i get this :

Request Method: | POST
-- | --
http://localhost:8000/auth/token/login/

Using the URLconf defined in backAPI.urls, Django tried these URL patterns, in this order:

    admin/
    auth/ ^users/$ [name='customuser-list']
    auth/ ^users\.(?P<format>[a-z0-9]+)/?$ [name='customuser-list']
    auth/ ^users/activation/$ [name='customuser-activation']
    auth/ ^users/activation\.(?P<format>[a-z0-9]+)/?$ [name='customuser-activation']
    auth/ ^users/me/$ [name='customuser-me']
    auth/ ^users/me\.(?P<format>[a-z0-9]+)/?$ [name='customuser-me']
    auth/ ^users/resend_activation/$ [name='customuser-resend-activation']
    auth/ ^users/resend_activation\.(?P<format>[a-z0-9]+)/?$ [name='customuser-resend-activation']
    auth/ ^users/reset_password/$ [name='customuser-reset-password']
    auth/ ^users/reset_password\.(?P<format>[a-z0-9]+)/?$ [name='customuser-reset-password']
    auth/ ^users/reset_password_confirm/$ [name='customuser-reset-password-confirm']
    auth/ ^users/reset_password_confirm\.(?P<format>[a-z0-9]+)/?$ [name='customuser-reset-password-confirm']
    auth/ ^users/reset_username/$ [name='customuser-reset-username']
    auth/ ^users/reset_username\.(?P<format>[a-z0-9]+)/?$ [name='customuser-reset-username']
    auth/ ^users/reset_username_confirm/$ [name='customuser-reset-username-confirm']
    auth/ ^users/reset_username_confirm\.(?P<format>[a-z0-9]+)/?$ [name='customuser-reset-username-confirm']
    auth/ ^users/set_password/$ [name='customuser-set-password']
    auth/ ^users/set_password\.(?P<format>[a-z0-9]+)/?$ [name='customuser-set-password']
    auth/ ^users/set_username/$ [name='customuser-set-username']
    auth/ ^users/set_username\.(?P<format>[a-z0-9]+)/?$ [name='customuser-set-username']
    auth/ ^users/(?P<pk>[^/.]+)/$ [name='customuser-detail']
    auth/ ^users/(?P<pk>[^/.]+)\.(?P<format>[a-z0-9]+)/?$ [name='customuser-detail']
    auth/ ^$ [name='api-root']
    auth/ ^\.(?P<format>[a-z0-9]+)/?$ [name='api-root']

The current path, auth/token/login/, didn't match any of these.

help please

gebolisasi commented 4 years ago

Try to add this code on your settings.py

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ],
}

and add this on your urls.py

path('auth/', include('djoser.urls.authtoken')),