我正在使用TurboGears 2.2.2。并且需要提供CSV文件以便用户可以下载。
这是我到目前为止的代码:
response.content_type = 'text/csv'
response.headers['Content-Disposition'] = 'attachment;filename=%s.csv' % file_name
listWriter = csv.writer(open(title+'.csv', 'wb'),
delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
listWriter.writerow(['foo', 'bar'])
with open (title+'.csv', "r") as myfile:
response.body=myfile.read().replace('\n', '')
return response
已创建CSV,但我无法将其提供给用户进行下载。我总是收到这个错误:
"TypeError: No object (name: response) has been registered for this thread"
请帮忙吗?
答案 0 :(得分:0)
ML:https://groups.google.com/d/msg/turbogears/T7Gly2TZv_s/-_JCMXNZqagJ
得到了答案返回response.body
代替response
将解决问题