timus2001 timus2001 - 2 years ago 136
HTTP Question

accessing request headers on django/python

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();

How to do this in python?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download