gpt4 book ai didi

django - 确定请求的内容类型?

转载 作者:行者123 更新时间:2023-12-03 13:21:03 25 4
gpt4 key购买 nike

我想编写一个 Django View ,它根据请求提供变体内容。例如,对于“text/xml”,提供 XML,对于“text/json”,提供 JSON 等。有没有办法从请求对象中确定这一点?像这样的东西会很棒:

def process(request):
if request.type == "text/xml":
pass
elif request.type == "text/json":
pass
else:
pass
HttpRequest上有房产吗?为了这?

最佳答案

HttpRequest.META ,更具体地说 HttpRequest.META.get('HTTP_ACCEPT') — 而不是 HttpRequest.META.get('CONTENT_TYPE')如前面提到的

关于django - 确定请求的内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7459881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com