【发布时间】:2014-10-14 10:53:39
【问题描述】:
我正在使用cherrypy 运行一个交互式网站,虽然生成CSV 的python 函数似乎正在工作(如果你直接与它交互,我的浏览器会下载它),它似乎并没有给用户这个CSV当我将它嵌入到表单请求中时文件:
<form id="export_csv_left" action="/c/flex_export_csv" method="get">
<input type="hidden" name="datakey" value="8TZbmRZ54IL7" >
<button type="button">Export stories and data as CSV</button>
</form>
我希望有一个按钮显示“导出 CSV”并返回文件。 该表单会向我的cherrypy 生成一个请求,如下所示:
djotjog.com/c/flex_export_csv?datakey=8TZbmRZ54IL7
cherrypy 部分内的标题是...
csv = make_csv(literal_eval(raw_data), filename)
cherrypy.response.headers['Content-Type'] = "application/x-download"
cherrypy.response.headers['Content-Disposition'] = ('attachment; filename= %s' % (filename,))
return csv
在浏览器中加载该链接会生成 CSV。那么表单的东西是怎么回事?
以下是一些我不太了解的可能相关的 javascript 控制台消息:
Denying load of chrome-extension://ganlifbpkcplnldliibcbegplfmcfigp/scripts/vendor/jquery/jquery.min.map. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.
以防万一。
【问题讨论】:
标签: python-2.7 csv cherrypy export-to-csv