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

yipeiwu_com5年前Python基础

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,这一句,同时上面的也只是一部分例子,因此在看文档的时候,希望同学们能细心一点!

以上这篇Django Python 获取请求头信息Content-Range的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python 输出列表元素实例(以空格/逗号为分隔符)

给定list,如何以空格/逗号等符号以分隔符输出呢? 一般的,简单的for循环可以打印出list的内容: l=[1,2,3,4] for i in l: print(i) 输出结...

python实现Virginia无密钥解密

本文实例为大家分享了Virginia无密钥解密的具体代码,供大家参考,具体内容如下 加密 virginia加密是一种多表替换加密方法,通过这种方法,可以有效的解决单表替换中无法应对的字...

Django集成搜索引擎Elasticserach的方法示例

1.背景 当用户在搜索框输入关键字后,我们要为用户提供相关的搜索结果。可以选择使用模糊查询 like 关键字实现,但是 like 关键字的效率极低。查询需要在多个字段中进行,使用 li...

python中copy()与deepcopy()的区别小结

python中copy()与deepcopy()的区别小结

前言 copy()与deepcopy()之间的区分必须要涉及到python对于数据的存储方式。 深复制被复制对象完全再复制一遍作为独立的新个体单独存在。所以改变原有被复制对象不会对已经复...

Python中使用PIL库实现图片高斯模糊实例

Python中使用PIL库实现图片高斯模糊实例

一、安装PIL PIL是Python Imaging Library简称,用于处理图片。PIL中已经有图片高斯模糊处理类,但有个bug(目前最新的1.1.7bug还存在),就是模糊半径写...