开发者

How to send zip file in http response in django? [duplicate]

This question already has answers here: 开发者_高级运维 Closed 12 years ago.

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:

  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).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜