From 02b94350acc564364a65633b4ca15b62e3cd3f00 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Thu, 13 May 2010 12:16:13 +0100 Subject: [PATCH] make sure that we 404 rather than 500 on people requesting pages that don't exist --- sommitrealweird/blog/views.py | 74 +++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/sommitrealweird/blog/views.py b/sommitrealweird/blog/views.py index 841b1ca..09ff5e4 100644 --- a/sommitrealweird/blog/views.py +++ b/sommitrealweird/blog/views.py @@ -16,23 +16,26 @@ def blog_index(request, section=None): page = int(request.GET.get('page', 1)) except ValueError: page = 1 - paginated_entries = paginator.page(page) - pages = paginator.page_range - t = loader.get_template("blog/blog_index.html") - c = RequestContext(request, - { - "entries": paginated_entries.object_list, - "title": settings.BLOG_TITLE, - "page": page, - "pages": pages, - "paginated": 1, - "has_more_than_one_page": (len(pages) > 1), - "has_next": paginated_entries.has_next(), - "has_prev": paginated_entries.has_previous(), - "next": page + 1, - "prev": page - 1 - }) - return HttpResponse(t.render(c)) + try: + paginated_entries = paginator.page(page) + pages = paginator.page_range + t = loader.get_template("blog/blog_index.html") + c = RequestContext(request, + { + "entries": paginated_entries.object_list, + "title": settings.BLOG_TITLE, + "page": page, + "pages": pages, + "paginated": 1, + "has_more_than_one_page": (len(pages) > 1), + "has_next": paginated_entries.has_next(), + "has_prev": paginated_entries.has_previous(), + "next": page + 1, + "prev": page - 1 + }) + return HttpResponse(t.render(c)) + except: + raise Http404 else: raise Http404 @@ -78,22 +81,25 @@ def blog_view(request, year=None, month=None, day=None, hour=None, minutes=None, page = int(request.GET.get('page', 1)) except ValueError: page = 1 - paginated_entries = paginator.page(page) - pages = paginator.page_range - t = loader.get_template("blog/blog_index.html") - c = RequestContext(request, - { - "entries": paginated_entries.object_list, - "title": settings.BLOG_TITLE, - "page": page, - "pages": pages, - "paginated": 1, - "has_more_than_one_page": (len(pages) > 1), - "has_next": paginated_entries.has_next(), - "has_prev": paginated_entries.has_previous(), - "next": page + 1, - "prev": page - 1 - }) - return HttpResponse(t.render(c)) + try: + paginated_entries = paginator.page(page) + pages = paginator.page_range + t = loader.get_template("blog/blog_index.html") + c = RequestContext(request, + { + "entries": paginated_entries.object_list, + "title": settings.BLOG_TITLE, + "page": page, + "pages": pages, + "paginated": 1, + "has_more_than_one_page": (len(pages) > 1), + "has_next": paginated_entries.has_next(), + "has_prev": paginated_entries.has_previous(), + "next": page + 1, + "prev": page - 1 + }) + return HttpResponse(t.render(c)) + except: + raise Http404 else: raise Http404 -- 2.39.5