[Fixed]-Access token from view


You can access them within a view using request.META, which is a dictionary.
So you can use request.META.get(‘HTTP_AUTHORIZATION’) to access autherizatoin token.

For more details visit Django TokenAuthentication missing the 'Authorization' http header

If you are deploying to Apache, and using any non-session based authentication, you will need to explicitly configure mod_wsgi to pass the required headers through to the application. This can be done by specifying the WSGIPassAuthorization directive in the appropriate context and setting it to ‘On’. For details please visit http://www.django-rest-framework.org/api-guide/authentication/


You can get the token from the request.auth attribute. It returns a DRF Token instance. If you want only the key then you can access it with the request.auth.key attribute.


Leave a comment