I have a problem with sending request as attachments in django. My application writes some data to files and zips it. However, when i return an attachment response, the browser downloads it but the zip file is corrupted. (The original zip contains my files and doesn't give any errors.)
My code is here:
file_path = "/root/Programs/media/statics/schedules/"
zip_file_name = file_path + "test.zip"
zip_file = zipfile.ZipFile(zip_file_name, "w")
for i in range(len(planner_list)):
file_name = file_path + str(planner_list[i][0].start_date)
render_to_file('deneme.html',file_name ,{'schedule':schedule})
zip_file.write(file_name, os.path.basename(file_name),zipfile.ZIP_DEFLATED)
os.remove(file_name)
zip_file.close()
response = HttpResponse(file_path , content_type='application/zip')
response['Content-Disposition'] = 'attachment; filename=test.zip'
return response