擅长:python、mysql、java
<pre><code>def zipFiles(files):
outfile = StringIO() # io.BytesIO() for python 3
with zipfile.ZipFile(outfile, 'w') as zf:
for n, f in enumarate(files):
zf.writestr("{}.csv".format(n), f.getvalue())
return outfile.getvalue()
zipped_file = zip_files(myfiles)
response = HttpResponse(zipped_file, content_type='application/octet-stream')
response['Content-Disposition'] = 'attachment; filename=my_file.zip'
</code></pre>
<p>StringIO有返回整个内容的<code>getvalue</code>方法。你可以压缩拉链
通过<code>zipfile.ZipFile(outfile, 'w', zipfile.ZIP_DEFLATED)</code>。压缩的默认值是<code>ZIP_STORED</code>,它将创建不压缩的zip文件。在</p>