Django Python 获取请求头信息Content-Range的方法

作者:lzj_lzj2014 时间:2022-09-09 07:04:53 

request请求头信息的键会加上HTTP_转换成大写存到request.META中

因此你只需要


content_range = request.META['HTTP_CONTENT_RANGE']

这样就可以获取到Content-Range的信息。

django官网的解释:

A standard Python dictionary containing all available HTTP headers. Available headers depend on the client and server, but here are some examples:

CONTENT_LENGTH – The length of the request body (as a string).
CONTENT_TYPE – The MIME type of the request body.
HTTP_ACCEPT – Acceptable content types for the response.
HTTP_ACCEPT_ENCODING – Acceptable encodings for the response.
HTTP_ACCEPT_LANGUAGE – Acceptable languages for the response.
HTTP_HOST – The HTTP Host header sent by the client.
HTTP_REFERER – The referring page, if any.
HTTP_USER_AGENT – The client's user-agent string.
QUERY_STRING – The query string, as a single (unparsed) string.
REMOTE_ADDR – The IP address of the client.
REMOTE_HOST – The hostname of the client.
REMOTE_USER – The user authenticated by the Web server, if any.
REQUEST_METHOD – A string such as "GET" or "POST".
SERVER_NAME – The hostname of the server.
SERVER_PORT – The port of the server (as a string).
With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.

很多同学在找Content-Range的时候发现文档中没有这个,所以以为不支持这个,一直再找。百度 Google什么的

但是其实这个文档只是列出的其中一部分,而且他们没细心的读A standard Python dictionary containing all available HTTP headers,这一句,同时上面的也只是一部分例子,因此在看文档的时候,希望同学们能细心一点!

来源:https://blog.csdn.net/lzj_lzj2014/article/details/60765651

标签:Django,Python,请求头
0
投稿

猜你喜欢

  • 详解Python图像处理库Pillow常用使用方法

    2022-07-17 11:04:53
  • pycharm 复制代码出现空格的解决方式

    2023-08-27 12:36:37
  • Django基础知识 web框架的本质详解

    2023-03-23 17:38:01
  • MySQL REVOKE实现删除用户权限

    2024-01-16 11:29:40
  • js算法实例之字母大小写转换

    2024-04-16 08:52:05
  • PyTorch 如何自动计算梯度

    2023-08-13 14:44:20
  • MySQL 原理与优化之Limit 查询优化

    2024-01-15 04:44:26
  • python 遗传算法求函数极值的实现代码

    2023-08-29 11:36:11
  • 浅析JSONP技术原理及实现

    2024-05-28 15:41:10
  • Vue2.0利用 v-model 实现组件props双向绑定的优美解决方案

    2024-05-02 17:09:28
  • Python 正则 re.compile 真的必需吗

    2021-12-27 17:12:24
  • python运用sklearn实现KNN分类算法

    2022-12-04 03:53:19
  • block 和 inline 答案揭晓~ 另付一则,关于 word-break

    2009-12-08 13:06:00
  • SQL分页查询方式汇总

    2024-01-24 00:33:29
  • mysql 8.0.28 安装配置方法图文教程

    2024-01-16 16:40:26
  • 10款最好的Python开发编辑器

    2022-02-14 07:35:28
  • 解决python中os.listdir()函数读取文件夹下文件的乱序和排序问题

    2022-10-24 05:34:54
  • InnoDB数据库死锁问题处理

    2024-01-19 13:30:59
  • MySQL中查看数据库安装路径的方法

    2024-01-16 04:19:46
  • vue-cli3.0 脚手架搭建项目的过程详解

    2023-07-02 17:05:09
  • asp之家 网络编程 m.aspxhome.com