flask-restful - flask_restful 响应的默认 mimetype(内容类型)
问题描述
对不起,也许这是一个有点愚蠢的问题,但我无法在文档或库的源代码中找到它flask_restful
。flask_restful 响应的默认内容类型是什么?
在我项目的所有库中,我发现以下内容:
- flask: default_mimetype = "text/html"
- werkzeug.sansio:
default_mimetype = "text/plain"
mimetype = get_content_type(mimetype, self.charset)
- werkzeug.utils: mimetype = application/octet-stream
从该行mimetype = get_content_type(mimetype, self.charset)
看起来它可能依赖于内容,但我正在返回一个字典:
class FooResource(Resource):
def get(self):
return {'hello': 'world'}, 200
我得到的内容类型是application/json
. 有人可以解释这种行为吗?application/json
即使没有在任何地方指定,我怎么可能获得内容类型?如果我需要确定内容类型是application/json
,明确返回它会更好吗?(我知道我可以在请求后使用)
class FooResource(Resource):
def get(self):
return {'hello': 'world'}, 200, {'Content-Type': 'application/json'}
非常感谢。
解决方案
推荐阅读
- angularjs - 如何在 MSAL 浏览器中使用来自 acquiretoken 静默的刷新令牌
- python - Python 命令 Pandas 系列数据比较
- dataframe - 如何使用谷歌表格在一张图表上绘制具有不同水平范围的多条线?
- html - 为什么100vh不走全屏?
- java - 如果用户不必要地单击保存按钮并且没有要保存的内容,如何检查 java?
- autorest - AutoRest v3 按控制器拆分 Rest Client
- asp.net-mvc - Knockout.js 中的数据绑定
- owasp - 如何在命令行中运行 ZAP 扫描?
- reactjs - 如何在使用反应测试库单击父组件上的按钮后测试子组件呈现文本?
- c# - 如何在更新中每次使用 foreach 循环一次,并且每次都使用 bool 标志?