Flask-RESTful - Return custom Response format

前端 未结 3 381
南旧
南旧 2021-02-01 06:23

I have defined a custom Response format as per the Flask-RESTful documentation as follow.

app = Flask(__name__)
api = restful.Api(app)

@api.representation(\'app         


        
3条回答
  •  情歌与酒
    2021-02-01 06:51

    What representation is used is determined by the request, the Accept header mime type.

    A request of application/octet-stream will be responded to by using your binary function.

    If you need a specific response type from an API method, then you'll have to use flask.make_response() to return a 'pre-baked' response object:

    def get(self):
        response = flask.make_response(something)
        response.headers['content-type'] = 'application/octet-stream'
        return response
    

提交回复
热议问题