www

更新时间:2021年6月29日 15:55  文章类型:  作者:www

123

Image

```python class Multi_File_DownLoad(View):

def get(self,request):

    return HttpResponse()

def post(self,request):

    filepathlist = request.POST.getlist('filelist')

    fzip = zipfile.ZipFile('temp.zip','w',zipfile.ZIP_DEFLATED)

    for filepath in filepathlist:
        fzip.write(filepath,filepath)

    fzip.close()

    file_zip = open('tmp.zip','rb')
    response = HttpResponse(file_zip)
    response['Content-Type'] = 'application/octet-stream'
    response['Content-Disposition'] = 'attachment;filename=tmp.zip'
    file_zip.close()
    return response

```