Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
python:flask:response_fichier [2021/11/07 06:54] marclebrun |
python:flask:response_fichier [2022/11/24 06:15] (Version actuelle) marclebrun |
||
---|---|---|---|
Ligne 13: | Ligne 13: | ||
@app.route("/export") | @app.route("/export") | ||
def export(): | def export(): | ||
- | result = { | + | |
- | 'nom' : 'Lebrun', | + | data = { |
- | 'prenom': 'Marc', | + | 'nom' : 'Dupont', |
+ | 'prenom': 'Albert', | ||
'age' : 50 | 'age' : 50 | ||
} | } | ||
+ | | ||
+ | filename = "export-" + datetime.datetime.now().strftime("%Y%m%d-%H%M") + ".json" | ||
+ | | ||
return Response( | return Response( | ||
- | json.dumps(result, indent=4), | + | json.dumps(data, indent=4), |
mimetype='application/json', | mimetype='application/json', | ||
headers={ | headers={ | ||
- | 'Content-Disposition': 'attachment; filename=donnees.json' | + | 'Content-Disposition': 'attachment; filename=' + filename |
} | } | ||
) | ) |