【发布时间】:2014-11-23 15:39:32
【问题描述】:
我正在使用 Turbogears 2.3.3 开发一个 web 应用程序
在我的应用程序中,用户将获得一组路线,他们需要相应地下载一些文件。
重要的是,他们将能够下载具有原始名称的文件,该名称将采用 utf8 格式。
这是我下载文件的方法:
import os
from webob.static import FileApp
from tg import expose, request, use_wsgi_app, response
....
@expose()
def download(self,**kw):
response.headerlist.append(('Content-Disposition','attachment'))
path_to_file = os.path.join(os.path.dirname(dfuswebapp.__file__), 'PrintFiles')
file_with_path = os.path.join(path_to_file,kw['filename'])
file = FileApp(file_with_path)
return use_wsgi_app(file)
当我尝试获取这样的文件时,文件名是“下载”,带有原始文件的扩展名。
如果我尝试这段代码:
response.headerlist.append(('Content-Disposition','attachment;filename=%s'%str(kw['filename'])))
如果 kw['filename'] 是 utf-8 格式,我会收到一个错误,我的大部分文件都是这样。
有没有办法获得原始文件名?
感谢您的帮助
【问题讨论】:
标签: python-2.7 utf-8 response turbogears2