[Django]-Authentication credentials were not provided drf

5👍

You can’t access the api from the browsers url if you are using TokenAuthentication.
as said by @DarkOrb TokenAuthentication expects a authorization header with token as it’s value.
So You must pass token whenever you call the api.
You can test your api using postman.

enter image description here

In above image i have passed token in headers of postman to access my api.
When you call your api from frontend side,pass your token along with the request.
If you just want to use your api in only desktop’s browser,in that case you can use SessionAuthentication only.For mobile devices Tokenauthentication must be done.

2👍

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES':(
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES':(
        'rest_framework.permissions.IsAuthenticated',
    )
}

use this in your settings.py file, what is happening is that rest_framework.authentication.TokenAuthentication expects a authorization header with token as it’s value, but you can’t send that with your browser, to browse API from browser you must have SessionAuthentication enabled.

👤AviKKi

Leave a comment