12👍
✅
You need to lookup HTTP_AUTHORIZATION
key instead of AUTHORIZATION
because Django appends HTTP_
prefix to the header name.
From the Django docs on request.META:
With the exception of
CONTENT_LENGTH
andCONTENT_TYPE
, any HTTP
headers in the request are converted to META keys by
converting all characters to uppercase, replacing any hyphens with
underscores and adding an HTTP_ prefix to the name. So, for example, a
header calledX-Bender
would be mapped to the META keyHTTP_X_BENDER
.
So, to retrieve the API key, you need to do:
API_key = request.META.get('HTTP_AUTHORIZATION')
Source:stackexchange.com