accessing request headers on django/python

You can access them within a view using request.META, which is a dictionary.

If you wanted the Authorization header, you could do request.META['HTTP_AUTHORIZATION']

If you're creating a restful API from scratch, you might want to take a look at using tastypie.


As of django 2.2 HttpRequest.headers were added to allow simple access to a request’s headers. So now you can also get authentication header using get() function on request.headers

request.headers.get('Authorization')

This will give you value token value back.

Bearer eyJ0eYourToken...

https://docs.djangoproject.com/en/2.2/ref/request-response/#django.http.HttpRequest.headers


You can use

request.META['HTTP_AUTHORIZATION']

and sometimes

request.META['Authorization']

can help.