I am making a jquery ajax POST request and passing the data to backend python code in Django framework. I need to return the zip file as httpresponse which should be automatically downloaded in browser.
object_body = request.body.decode('utf-8')
loaded_json = json.loads(object_body)
json_obj = ast.literal_eval(str(loaded_json))
zip_file_path = importexport.download(json_obj,user)
zip_filename = os.path.basename(zip_file_path)
with open(zip_file_path, 'rb') as zip:
response = HttpResponse(zip.read(), content_type = 'application/x-zip')
response['Content-Disposition'] = 'attachment; filename=' + zip_filename
return response