在特定情况下,我想以text/html
内容类型回复错误,如下所示:
class MyResource(Resource):
def get(self):
if some_condition:
return 'bad argument', 400
上面的代码会返回application/json
内容类型:'"bad argument"'
而不是text/html
内容类型:'bad argument'
如何使用text/html
内容类型强制使用burn-restful来回复?
答案 0 :(得分:3)
您必须使用flask.make_response()
返回预先出炉的'响应对象:
return flask.make_response('bad argument', 400)
Flask-Restful将不加改变地传递全部Response
个对象,而不是尝试将它们转换为特定的请求mime类型。