访问django / python上的请求标头

时间:2022-06-05 12:57:10

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

我需要使用sencha和django创建一个安全的restFUL api。我对python很新。到目前为止,我能够使用基本身份验证从sencha向服务器发送请求,如下所示

 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

在php / apache中,我可以使用下面的代码轻松访问这些标题

$headers = apache_request_headers();
print_r($headers);

How to do this in python?

如何在python中执行此操作?

1 个解决方案

#1


27  

You can access them within a view using request.META, which is a dictionary.

您可以使用request.META(一个字典)在视图中访问它们。

If you wanted the Authorization header, you could do request.META['HTTP_AUTHORIZATION']

如果你想要Authorization标头,你可以做request.META ['HTTP_AUTHORIZATION']

If you're creating a restful API from scratch, you might want to take a look at using tastypie.

如果您从头开始创建一个安静的API,您可能需要查看使用tastypie。

#1


27  

You can access them within a view using request.META, which is a dictionary.

您可以使用request.META(一个字典)在视图中访问它们。

If you wanted the Authorization header, you could do request.META['HTTP_AUTHORIZATION']

如果你想要Authorization标头,你可以做request.META ['HTTP_AUTHORIZATION']

If you're creating a restful API from scratch, you might want to take a look at using tastypie.

如果您从头开始创建一个安静的API,您可能需要查看使用tastypie。