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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If all your responses will have only one response content-type this approach is pretty useful (implemented on the flask app declaration):
'application/json' as my default response type for a basic API