DeadDjangoDjoker
DeadDjangoDjoker

Reputation: 602

Handle a request header in Django rest framework to get the secret key passed in the header?

I have a django backend for a mobile app.

Im using django rest framework, but im still writing my own views and logic because the api end points are not model based.

The request sent to me has a secret key in the headers which is associated to individual devices registered. Along with it it has post data consisting of device id and other details.

How do i access the secret key value from the header if i am writing my own custom views in django to check if the device id and the secret key passed, matches?

Upvotes: 9

Views: 12134

Answers (1)

djangonaut
djangonaut

Reputation: 7778

It's not different from a regular django view:

class MyAPIView(APIView):
    def post(self, request, *args, **kwargs): 
        print self.request.META.get('HTTP_SECRET_KEY', None) 

A standard Python dictionary containing all available HTTP headers. Available headers depend on the client and server...

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

Upvotes: 11

Related Questions