python - Use Flask to convert a Pandas dataframe to CSV and serve a download -
i have pandas dataframe in flask app want return csv file.
return response(df.to_csv())
the problem output appears in browser instead of downloading separate file. how can change that?
i tried following gave empty output.
response = make_response(df.to_csv()) response.headers['content-type'] = 'text/csv' return response(response)
set content-disposition
tell browser download file instead of showing content on page.
resp = make_response(df.to_csv()) resp.headers["content-disposition"] = "attachment; filename=export.csv" resp.headers["content-type"] = "text/csv" return resp
Comments
Post a Comment