How to send zip file in http response in django? [duplicate]
Possible Duplicate:
Generating file to download with Django
I have a zip folder which has some file. I want to send those zip folder for some response in django. How can I do It?
The others are right, this has been asked.
However, basically you should be able to se
You can use the Python module 'zipfile' to generate the actual archive, but you mentioned you have the zipfile already?
from django.http import HttpResponse
...
response = HttpResponse(wrapper, content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=your_zipfile.zip'
return response
You'll need to add stuff to the above - perhaps some more info on where this file is coming from, or how you're generating it? But the above should get you started.
Cheers, Victor
Sending file attachments in responses is covered in the documentation.
Two things specific to your case that the docs don't mention:
- You need to pass the file data as the first argument to
HttpResponse()
(my_data
in the example). - You need the proper mimetype (
application/zip
).
精彩评论