I'm now making website that downloads certain images from other website, zip files, and let users download the zip file.
Everything works great, but I have no way to delete zip file from server, which has to be deleted after users download it.
I tried deleting temp directory that contains zip file with shutil.rmtree, but I couldn't find way to run it after HTTPResponse.
Here is my code in views.py.
zipdir = condown(idx)#condown creates zip file in zipdir
logging.info(os.path.basename(zipdir))
if os.path.exists(zipdir):
with open(zipdir, 'rb') as fh:
response = HttpResponse(fh.read(), content_type="multipart/form-data")
response['Content-Disposition'] = 'inline; filename=download.zip'
return response
raise Http404
Thanks in advance.