1import os
2from django.conf import settings
3from django.http import HttpResponse, Http404
4
5def download(request, path):
6 file_path = os.path.join(settings.MEDIA_ROOT, path)
7 if os.path.exists(file_path):
8 with open(file_path, 'rb') as fh:
9 response = HttpResponse(fh.read(), content_type="application/vnd.ms-excel")
10 response['Content-Disposition'] = 'inline; filename=' + os.path.basename(file_path)
11 return response
12 raise Http404
13