在Django / Python上访问请求标头 [英] accessing request headers on django/python
问题描述
我需要使用sencha和django创建一个安全的restFUL api。我对python相当陌生。到目前为止,我已经能够使用以下基本身份验证将请求从sencha发送到服务器
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="
}
}
})
在php / apache中,我可以使用以下代码轻松访问这些标头
In php/apache i can access those header with ease with the code below
$headers = apache_request_headers();
print_r($headers);
如何在python中做到这一点?
How to do this in python?
推荐答案
您可以使用 request.META
在视图中访问它们,
You can access them within a view using request.META
, which is a dictionary.
如果您想要Authorization标头,则可以执行 request.META ['HTTP_AUTHORIZATION']
If you wanted the Authorization header, you could do request.META['HTTP_AUTHORIZATION']
如果要从头开始创建一个宁静的API,则可能需要使用 tastypie 。
If you're creating a restful API from scratch, you might want to take a look at using tastypie.
这篇关于在Django / Python上访问请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!