0

を使用してzipファイルをダウンロードしたいDjango views。スタックオーバーフローで多くの解決策を経験しました。しかし、ファイルはまったくダウンロードされません。これが私が使用しているコードです。

誰でも、どこが間違っているのか教えてください。

response = HttpResponse(mimetype='application/zip')
response['Content-Disposition'] = 'attachment; filename=%s' % doc[Zip_file_name]
response['X-Sendfile'] = "./Zipfiles" # the path where the zip files are stored
return response

chromeを使用し、タブに表示されているinspect elementをダブルクリックすると、 get 要求として認識されるためファイルがダウンロードされますが、何も起こりません。urlnetworkhttpbutton click

助けてください。

4

1 に答える 1

0
from django.http import HttpResponse
from django.core.servers.basehttp import FileWrapper

# file
response = HttpResponse(FileWrapper(myfile), content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=myfile.zip'
return response
于 2013-02-11T06:48:14.490 に答える