Python Flask API 返回 CSV 内容但未下载文件 (Google Chrome)
Python Flask API Returning CSV Content But File Not Downloading (Google Chrome)
我已经根据用户在 Web 应用程序中填写表单的内容向用户编写了 API 到 return 的 CSV。当 运行 下面的代码时,我可以在我的控制台中看到响应,并且确定我的 API 正确地 return 编辑了内容,但我似乎无法获得文件自动开始下载。
csv = final_df.to_csv()
response = make_response(csv)
response.headers['Content-Disposition'] = "attachment; filename=export.csv"
response.headers['Content-type'] = "application/force-download"
return response
我的一个工作示例的不同之处在于引用文件名(Developer Docs 提示需要),并使用正确的 mimetype。
尝试
return bytes(csv, encoding='UTF-8'), 200, {
'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename="export.csv"'}
我已经根据用户在 Web 应用程序中填写表单的内容向用户编写了 API 到 return 的 CSV。当 运行 下面的代码时,我可以在我的控制台中看到响应,并且确定我的 API 正确地 return 编辑了内容,但我似乎无法获得文件自动开始下载。
csv = final_df.to_csv()
response = make_response(csv)
response.headers['Content-Disposition'] = "attachment; filename=export.csv"
response.headers['Content-type'] = "application/force-download"
return response
我的一个工作示例的不同之处在于引用文件名(Developer Docs 提示需要),并使用正确的 mimetype。
尝试
return bytes(csv, encoding='UTF-8'), 200, {
'Content-Type': 'text/csv',
'Content-Disposition': 'attachment; filename="export.csv"'}