【发布时间】:2016-05-06 13:47:54
【问题描述】:
我想通过特定的路线向用户返回带有一些结果的 .txt。 所以我有:
@route('/export')
def export_results():
#here is some data gathering ot the variable
return #here i want to somehow return on-the-fly my variable as a .txt file
所以,我知道如何:
- 打开、返回 static_file(root='blahroot',filename='blah')、关闭、取消链接
- 使用“import tempfile”等进行一些类似的操作
但是:我听说我可以以某种特定方式设置响应 http 标头,将我的变量作为文本返回将由浏览器(如文件)获取。
问题是:如何让它这样运行?
P.S.:如标签所示,我在 Python3 上,使用 Bottle 并计划将来自 cherrypy 的服务器用作 wsgi 服务器
【问题讨论】:
标签: python http python-3.x http-headers bottle