如何在Flask-RESTful中添加自定义HTTP响应标头? [英] How to add custom HTTP response header in Flask-RESTful?
本文介绍了如何在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'}
这篇关于如何在Flask-RESTful中添加自定义HTTP响应标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文