class TestView(APIView):
def get(self,request):
try:
response = HttpResponse(content_type=‘application/zip‘)
zf = zipfile.ZipFile(response,‘w‘)
zf.writestr("qqqq","nihao")
response[‘Content-Disposition‘] = ‘attachment; filename=myfile.zip‘
return response
except Exception as e:
return Response(str(e))

原文:https://www.cnblogs.com/weidaijie/p/11759347.html