Django获取request header信息
request.META.get("xxx ") 用于獲取header的信息
注意的是header key必須增加前綴HTTP,同時大寫,例如你的key為username,那么應(yīng)該寫成:request.META.get("HTTP_USERNAME")
另外就是當(dāng)你的header key中帶有中橫線,那么自動會被轉(zhuǎn)成下劃線,例如my-user的寫成: request.META.get("HTTP_MY_USER")
eg:
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).
總結(jié)
以上是生活随笔為你收集整理的Django获取request header信息的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: jquery php联动,jQuery结
- 下一篇: Cookiecutter