From 46c161fcd693ffabe8b08c9aae117c902c8c8824 Mon Sep 17 00:00:00 2001 From: hernani Date: Tue, 11 May 2010 00:06:04 +0000 Subject: [PATCH] Raise 404 when the page number does not exist. git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@207 0cfe37f9-358a-4d5e-be75-b63607b5c754 --- forum/views/decorators.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/forum/views/decorators.py b/forum/views/decorators.py index 141887a..f9929ff 100644 --- a/forum/views/decorators.py +++ b/forum/views/decorators.py @@ -1,6 +1,6 @@ -from django.http import HttpResponse, HttpResponseRedirect +from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.utils import simplejson -from django.core.paginator import Paginator +from django.core.paginator import Paginator, EmptyPage from django.shortcuts import render_to_response from django.template import RequestContext from django.utils.translation import ungettext, ugettext as _ @@ -29,7 +29,11 @@ def list(paginate, default_page_size): big_list = context[paginate] paginator = Paginator(big_list, pagesize) - page_obj = paginator.page(page) + try: + page_obj = paginator.page(page) + except EmptyPage: + raise Http404() + context[paginate] = page_obj.object_list.lazy() base_path = context.get('base_path', None) or request.path -- 2.39.5