私はディスク上にファイルを作成することを避けています、これは私がこれまでに得たものです:
def get_zip(request):
import zipfile, StringIO
i = open('picture.jpg', 'rb').read()
o = StringIO.StringIO()
zf = zipfile.ZipFile(o, mode='w')
zf.writestr('picture.jpg', i)
zf.close()
o.seek(0)
response = HttpResponse(o.read())
o.close()
response['Content-Type'] = 'application/octet-stream'
response['Content-Disposition'] = "attachment; filename=\"picture.zip\""
return response
あなたは正しい-エレガント-pythonicで十分だと思いますか?それを行うためのより良い方法はありますか?
ありがとう!