【python – 使用flask-restful时返回text / html内容类型】教程文章相关的互联网学习教程文章

python – 使用flask-restful时返回text / html内容类型【代码】

在特定情况下,我想用text / html内容类型来回复错误,如下所示:class MyResource(Resource):def get(self):if some_condition:return 'bad argument', 400上面的代码返回一个application / json content-type:’“bad argument”’而不是text / html内容类型:’bad argument’ 我怎样才能强制使用文本/ html内容类型来回复烧瓶?解决方法:您必须使用flask.make_response()返回“预烘焙”响应对象:return flask.make_response('b...