Return text / html content-type when using flask-restful

In a specific case, I would like to answer with the content-type text/html

for the error like this:

class MyResource(Resource):
    def get(self):
        if some_condition:
            return 'bad argument', 400

      

The above code returns a application/json

content-type: '"bad argument"'


instead of the text/html

content-type:'bad argument'

How can I force a flask with a content type to react text/html

?

+3


source to share


1 answer


You will need to use flask.make_response()

to return the "pre-baked" response object:

return flask.make_response('bad argument', 400)

      



Flask-Restful will pass objects Response

unchanged, rather than trying to convert them to the given mime type.

+2


source







All Articles