所以我想下载csv作为附件,但我能够看到它在浏览器本身,而不是附件。 这是我的烧瓶密码-
@app.route('/submit', methods=['POST'])
*Some Code*
df = calc.get_data(prdrop,fr_value,sumprfit,fitids) # got dataframe
session["df"] = df.to_csv(index=False,header=True, sep=",")
return render_template('plot.html',url=plot_url) #renders a plot from html
@app.route("/download", methods=["POST"])
def download():
df=session["df"]
return df if "df" in session else ""
我想以csv的身份得到这个文件,有人能帮忙吗?
我得到了答案-
我应该创建get_response
def download():
df = session["df"]
response = make_response(df)
cd = 'attachment; filename=mycsv.csv'
response.headers['Content-Disposition'] = cd
response.mimetype = 'text/csv'
return response