字典是通过 render_template(‘team_result.html’, qadict=teamdata, msg=msg )传到前端,需要做的操作是将这个字典teamdata传给另一个路由,用来将这个字典转成Excel导出,先在导出功能实现了,但是用的是全局变量法 感觉不是很nice,如何用post/get或者ajax方法将字典直接传到/export,然后在导出,export代码如下。
> @app.route("/export" ) > def export(): > # export excel > output = BytesIO() > writer = pd.ExcelWriter(output, engine='xlsxwriter') > team_all.to_excel(writer, sheet_name='Sheet1', index=False) > workbook = writer.book > worksheet = writer.sheets['Sheet1'] > writer.close() > output.seek(0) > resp = make_response(output.getvalue()) > resp.headers["Content-Disposition"] = "attachment; filename=testing.xlsx" > resp.headers['Content-Type'] = 'application/x-xlsx' > return resp