1

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?

Community
  • 1
  • 1
smmittal
  • 15
  • 1
  • 1
  • 3

2 Answers2

3

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

victorhooi
  • 16,775
  • 22
  • 90
  • 113
  • @smmittal Did the above text answer your question? If so, perhaps you might mark it as answered please? Or if not, perhaps give some more specifics, and we can try and help you further. – victorhooi Apr 19 '11 at 08:13
  • 5
    I find it unclear what `wrapper` is. You don't define it... – jonalv Jun 02 '16 at 13:33
0

Sending file attachments in responses is covered in the documentation.

Two things specific to your case that the docs don't mention:

  1. You need to pass the file data as the first argument to HttpResponse() (my_data in the example).
  2. You need the proper mimetype (application/zip).
Paul Bissex
  • 1,611
  • 1
  • 17
  • 22