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.
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.
- [Django]-How do I call templates with same names at different directories in Django?
- [Django]-JSON decode error while sending post request during testing
- [Django]-How does Django determine if an uploaded image is valid?
- [Django]-Customize Django Admin Change Form Foreignkey to Include View Record
- [Django]-Example Cron with Django