Created
November 15, 2013 09:17
-
-
Save yejianye/7481508 to your computer and use it in GitHub Desktop.
Set mime type of response object in Flask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/download', methods=['GET']) | |
def download(): | |
data = json.dumps({"example" : "json string"}) | |
response = make_response(data) | |
response.headers['Content-Type'] = 'text/json' | |
response.headers['Content-Disposition'] = 'attachment; filename=example.json' | |
return response |
If all your responses will have only one response content-type this approach is pretty useful (implemented on the flask app declaration):
@app.after_request
def after_request_func(data):
response = make_response(data)
response.headers['Content-Type'] = 'application/json'
return response
'application/json' as my default response type for a basic API
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how could i send token in header in flask restful api