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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -