在 django/python 上访问请求标头

2023-02-14Python开发问题
4

本文介绍了在 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']

如果您从头开始创建一个 RESTful API,您可能想看看使用 tastypie.

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

这篇关于在 django/python 上访问请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

在xarray中按单个维度的多个坐标分组
groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)...
2024-08-22 Python开发问题
15

Pandas中的GROUP BY AND SUM不丢失列
Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)...
2024-08-22 Python开发问题
17

GROUP BY+新列+基于条件的前一行抓取值
Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)...
2024-08-22 Python开发问题
18

PANDA中的Groupby算法和插值算法
Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)...
2024-08-22 Python开发问题
11

PANAS-基于列对行进行分组,并将NaN替换为非空值
Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)...
2024-08-22 Python开发问题
10

按10分钟间隔对 pandas 数据帧进行分组
Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)...
2024-08-22 Python开发问题
11