Return a 404 error for non-existent pages

This commit is contained in:
Rodolphe Breard 2018-02-04 11:25:02 +01:00
parent 71e7433040
commit eb8a3688a5

View file

@ -1,5 +1,5 @@
from django.http import HttpResponseRedirect, Http404
from django.utils.translation import get_language
from django.http import HttpResponseRedirect
from django.views import generic
from django.urls import reverse
from .models import Page, PageContent
@ -16,7 +16,10 @@ class PageView(generic.DetailView):
template_name = 'pages/page.html'
def get_object(self):
return PageContent.objects.filter(
obj = PageContent.objects.filter(
language=get_language(),
page__slug=self.kwargs['slug']
).first()
if obj is None:
raise Http404('Page not found: %s' % self.kwargs['slug'])
return obj