django zip文件没有得到下载

问题描述:

我想用Django views下载zip文件。我在堆栈溢出中经历了许多解决方案。但该文件根本没有下载。这是我正在使用的代码。django zip文件没有得到下载

任何人都可以告诉我哪里出错了。

response = HttpResponse(mimetype='application/zip') 
response['Content-Disposition'] = 'attachment; filename=%s' % doc[Zip_file_name] 
response['X-Sendfile'] = "./Zipfiles" # the path where the zip files are stored 
return response 

chrome,如果我使用inspect element,并双击在network选项卡中显示的url,因为它被认为是一个http get请求的文件被下载,而在button click没有任何反应。

请帮忙。

+0

请参阅本之一:http://stackoverflow.com/questions/5935014/returning-zip-for-download-from-view-in-django – catherine 2013-02-11 05:13:22

+0

感谢......我想,也... din't似乎没有工作... – user1986873 2013-02-11 06:43:36

from django.http import HttpResponse 
from django.core.servers.basehttp import FileWrapper 

# file 
response = HttpResponse(FileWrapper(myfile), content_type='application/zip') 
response['Content-Disposition'] = 'attachment; filename=myfile.zip' 
return response 
+0

如果zip文件存在于不同的位置..我应该通过路径FileWrapper对吗? – user1986873 2013-02-11 08:56:32

+0

y ........... – catherine 2013-02-11 08:58:09

+0

我得到这个错误 - 错误 - 'unicode'对象没有属性'读' FileWrapper可以直接用于zip文件? ,如果我把FileWrapper(打开(myFile))...在响应中,它只显示单个文件名已被压缩... – user1986873 2013-02-11 09:08:13