Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 620
DeadDjangoDjoker Avatar asked Mar 19 '15 08:03

DeadDjangoDjoker


1 Answers

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

like image 122
djangonaut Avatar answered Sep 29 '22 02:09

djangonaut