From b16fe7d68e48d58c6e9ce553c7c4363704189ae7 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 23 May 2020 12:23:03 +0200 Subject: [PATCH] 404 error rather than 403 when media is not found --- apps/member/views.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/member/views.py b/apps/member/views.py index 0820922..fa8aeeb 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -4,7 +4,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.models import AnonymousUser from django.core.exceptions import PermissionDenied from django.db.models import Q -from django.http import FileResponse +from django.http import FileResponse, Http404 from django.shortcuts import redirect from django.urls import reverse_lazy from django.utils import timezone @@ -188,7 +188,11 @@ class DocumentView(LoginRequiredMixin, View): """ def get(self, request, *args, **kwargs): - doc = Document.objects.get(file=self.kwargs["file"]) + try: + doc = Document.objects.get(file=self.kwargs["file"]) + except Document.DoesNotExist: + raise Http404(_("No %(verbose_name)s found matching the query") % + {'verbose_name': Document._meta.verbose_name}) grant = request.user.admin