In a specific case I'd like to respond with a text/html content-type for an error as follows:
class MyResource(Resource):
    def get(self):
        if some_condition:
            return 'bad argument', 400
The code above returns an application/json content-type: '"bad argument"'
instead of a text/html content-type: 'bad argument'
How can I force flask-restful to respond with text/html content-type?
You'll have to use flask.make_response() to return a 'pre-baked' response object:
return flask.make_response('bad argument', 400)
Flask-Restful will pass full-on Response objects unaltered, rather than try and convert them to a specific requested mime type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With