作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在从 Django header 获取数据时遇到问题。
我的 API 使用 CURL:-
curl -X POST \
https://xyx.com \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'xyzId: 3223' \
-H 'abcData: ABC-123' \
-d '{
"name": "xyz",
"dob": "xyz",
"user_info": "xyz",
}'
在我的 API 中,我需要获取 xyzId
和 abcData
我尝试了 request.META['abcData']
但出现错误 KeyError
。
如何在我的 View 中获取这两个数据?
请帮我解决这个问题。
提前致谢。
最佳答案
根据文档说 https://docs.djangoproject.com/en/2.0/ref/request-response/#django.http.HttpRequest.META
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.
所以你应该能够像这样访问你的标题
request.META['HTTP_ABCDATA']
关于python - 如何从 Django Headers 获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50584249/
我是一名优秀的程序员,十分优秀!