django zip文件不';无法下载

django zip文件不';无法下载,django,download,Django,Download,我想使用Django视图下载zip文件。我在堆栈溢出中经历了许多解决方案。但该文件根本无法下载。这是我正在使用的代码 谁能告诉我哪里出了问题 response = HttpResponse(mimetype='application/zip') response['Content-Disposition'] = 'attachment; filename=%s' % doc[Zip_file_name] response['X-Sendfile'] = "./Zipfiles" # the pa

我想使用
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元素
,双击
network
选项卡中显示的
url
,文件会被下载,因为它被识别为
http
get请求,而在
按钮上单击
则不会发生任何事情


请帮助。

参考此项:谢谢……我也尝试过……似乎不起作用……如果zip文件位于其他位置……我应该将路径传递到FileWrapper right??我收到此错误-错误-“unicode”对象没有属性“read”FileWrapper可直接用于zip文件??如果我把FileWrapper(open(myFile))…放在响应中,它只会显示已压缩的单个文件名…
download_url=“./Zipfiles/”+doc[Zip_file_name]response=HttpResponse(FileWrapper(open(download_url)),content_type='application/Zip')response['content-Disposition']='附件;文件名=%s'%doc[Zip\u file\u name]
我没有在代码中添加下载url。也许您可以将文件名更改为您的文件名位置。响应['Content-Disposition']='附件;filename=filename\u path‘我们稍后再谈,我先吃晚饭
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