Return a 404 error for non-existent pages
This commit is contained in:
parent
71e7433040
commit
eb8a3688a5
1 changed files with 5 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
|
from django.http import HttpResponseRedirect, Http404
|
||||||
from django.utils.translation import get_language
|
from django.utils.translation import get_language
|
||||||
from django.http import HttpResponseRedirect
|
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from .models import Page, PageContent
|
from .models import Page, PageContent
|
||||||
|
@ -16,7 +16,10 @@ class PageView(generic.DetailView):
|
||||||
template_name = 'pages/page.html'
|
template_name = 'pages/page.html'
|
||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
return PageContent.objects.filter(
|
obj = PageContent.objects.filter(
|
||||||
language=get_language(),
|
language=get_language(),
|
||||||
page__slug=self.kwargs['slug']
|
page__slug=self.kwargs['slug']
|
||||||
).first()
|
).first()
|
||||||
|
if obj is None:
|
||||||
|
raise Http404('Page not found: %s' % self.kwargs['slug'])
|
||||||
|
return obj
|
||||||
|
|
Loading…
Reference in a new issue