you can return json file from your flask server without creating it.
Created
November 9, 2021 13:01
-
-
Save jakbin/826195885cecec6604d7fd93b75f6932 to your computer and use it in GitHub Desktop.
download or stream json file from flask server
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
from flask import Flask, Response, json | |
app = Flask(__name__) | |
data = {'name':'jakbin', 'age':24} | |
# you can generate dynamic json data | |
a = 'jak' | |
@app.route('/') | |
def home(): | |
return Response(json.dumps(data, indent=3), mimetype='application/json', | |
headers={'Content-Disposition':f'attachment;filename={a}.json'}) | |
# you can generate dynamic file name | |
if __name__ == "__main__": | |
app.run(debug=True,) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment