Django Python 獲取請求頭信息Content-Range的方法
request請求頭信息的鍵會加上HTTP_轉(zhuǎn)換成大寫存到request.META中
因此你只需要
content_range = request.META['HTTP_CONTENT_RANGE']
這樣就可以獲取到Content-Range的信息。
django官網(wǎng)的解釋:
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的時候發(fā)現(xiàn)文檔中沒有這個,所以以為不支持這個,一直再找。百度 Google什么的
但是其實這個文檔只是列出的其中一部分,而且他們沒細心的讀A standard Python dictionary containing all available HTTP headers,這一句,同時上面的也只是一部分例子,因此在看文檔的時候,希望同學們能細心一點!
以上這篇Django Python 獲取請求頭信息Content-Range的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解Python如何批量采集京東商品數(shù)據(jù)流程
這不快過年了,又是要買年貨,又是要給女朋友買禮物的,分析一下價格,看看哪些是真的降價了2022-01-01Python函數(shù)isalnum用法示例小結(jié)
isalnum()函數(shù)是Python中的一個內(nèi)置函數(shù),用于判斷字符串是否只由數(shù)字和字母組成,其內(nèi)部實現(xiàn)原理比較簡單,只需遍歷字符串中的每一個字符即可,這篇文章主要介紹了Python函數(shù)isalnum用法介紹,需要的朋友可以參考下2024-01-01Python Tornado框架輕松寫一個Web應用的全過程
Tornado全稱Tornado Web Server,是一個用Python語言寫成的Web服務器兼Web應用框架,Tornado走的是少而精的方向,注重的是性能優(yōu)越,它最出名的是異步非阻塞的服務器方式,這篇文章主要給大家介紹了關(guān)于Python Tornado框架輕松寫一個Web應用的相關(guān)資料,需要的朋友可以參考下2021-08-08