Django Serve .xlsx File And Force Download
I'm currently using openPYXL in order to open a template file within Django module_dir = os.path.dirname(__file__) # get current directory file_path = os.path.join(module_dir
Solution 1:
You're not ever putting the file contents into the response, so naturally it is 0 bytes. X-Sendfile
is for a completely different purpose - when you're redirecting to a static server - and needs a URL, not a file path, anyway.
file_path = os.path.join(os.path.dirname(os.path.realpath(__name__)), 'EvalofSelf1.xlsx')
response = HttpResponse(open(file_path, 'rb').read())
response['Content-Type'] = 'mimetype/submimetype'
response['Content-Disposition'] = 'attachment; filename=DownloadedEval.xlsx'
Post a Comment for "Django Serve .xlsx File And Force Download"