I need to create a secure restFUL api using sencha and django. I am fairly new to python. So far i am able to send request from sencha to server using basic authentication as below
new Ext.data.Store({ proxy: { type: "ajax", headers: { "Authorization": "Basic asdjksdfsksf=" } } })
In php/apache i can access those header with ease with the code below
$headers = apache_request_headers(); print_r($headers);
How to do this in python?
To get all headers, you can use request. headers. keys() or request. headers.
It's possible that a request can come in via POST with an empty POST dictionary -- if, say, a form is requested via the POST HTTP method but does not include form data. Therefore, you shouldn't use if request. POST to check for use of the POST method; instead, use if request. method == "POST" (see above).
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.
You can use
request.META['HTTP_AUTHORIZATION']
and sometimes
request.META['Authorization']
can help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With