django force download file

Solutions on MaxInterview for django force download file by the best coders in the world

showing results for - "django force download file"
Maud
30 Jan 2018
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
similar questions
queries leading to this page
django force download file