How to add custom HTTP response header in Flask-RESTful?

送分小仙女□ 提交于 2020-06-17 06:28:45

问题


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?


回答1:


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'}


来源:https://stackoverflow.com/questions/38080310/how-to-add-custom-http-response-header-in-flask-restful

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!