Commit 57b9f09127e84051109cdcf3557ad6d069f5121f
1 parent
29a31a64
Exists in
master
and in
3 other branches
Adding file path inexist handler
Showing
1 changed file
with
4 additions
and
1 deletions
Show diff stats
file_link/views.py
1 | 1 | from django.shortcuts import get_object_or_404, redirect, render |
2 | -from django.http import HttpResponse | |
2 | +from django.http import HttpResponse, Http404 | |
3 | 3 | from os import path |
4 | 4 | from django.views import generic |
5 | 5 | from django.contrib import messages |
... | ... | @@ -35,6 +35,9 @@ class DownloadFile(LoginRequiredMixin, generic.DetailView): |
35 | 35 | slug = self.kwargs.get('slug', '') |
36 | 36 | file_link = get_object_or_404(FileLink, slug = slug) |
37 | 37 | |
38 | + if not path.exists(file_link.file_content.path): | |
39 | + raise Http404() | |
40 | + | |
38 | 41 | response = HttpResponse(open(file_link.file_content.path, 'rb').read()) |
39 | 42 | response['Content-Type'] = 'application/force-download' |
40 | 43 | response['Pragma'] = 'public' | ... | ... |