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


猜你喜欢
详解Python图像处理库Pillow常用使用方法
pycharm 复制代码出现空格的解决方式

Django基础知识 web框架的本质详解
MySQL REVOKE实现删除用户权限
js算法实例之字母大小写转换

PyTorch 如何自动计算梯度

MySQL 原理与优化之Limit 查询优化

python 遗传算法求函数极值的实现代码
浅析JSONP技术原理及实现
Vue2.0利用 v-model 实现组件props双向绑定的优美解决方案
Python 正则 re.compile 真的必需吗

python运用sklearn实现KNN分类算法

block 和 inline 答案揭晓~ 另付一则,关于 word-break

SQL分页查询方式汇总
mysql 8.0.28 安装配置方法图文教程

10款最好的Python开发编辑器

解决python中os.listdir()函数读取文件夹下文件的乱序和排序问题

InnoDB数据库死锁问题处理
MySQL中查看数据库安装路径的方法

vue-cli3.0 脚手架搭建项目的过程详解
