如何在Flask-RESTful中添加自定义HTTP响应标头?
问题描述:
我正在使用Flask-RESTful,并且想通过在响应中添加自定义HTTP标头来处理某些错误.有标准的Flask或Flask-RESTful方法吗?
I am using Flask-RESTful and would like to handle certain errors by adding a custom HTTP header to my response. Is there a standard Flask or Flask-RESTful way of doing this?
答
结果我跳过了文档的那一部分:
Turns out I skipped over that part of the docs:
class Todo3(Resource):
def get(self):
# Set the response code to 201 and return custom headers
return {'task': 'Hello world'}, 201, {'Etag': 'some-opaque-string'}