Closed GoogleCodeExporter closed 8 years ago
just hit the same problem. I remember I get 404 page when I access page out of
the range. I think 404 page is
appropriate...
Original comment by yash...@gmail.com
on 7 Nov 2008 at 6:38
I get this a lot too. It's be nice to be able to handle this error in the
template context somehow.
Original comment by npbor...@gmail.com
on 7 Nov 2008 at 3:38
Agreed, I think the solution is to insert an invalid_page value or something
into the
context, so that it's up to the template author to gracefully handle that and
not
attempt to use pagination if there is an invalid_page == True. Of course the
default
template will handle it correctly as well.
Original comment by flo...@gmail.com
on 7 Nov 2008 at 5:59
The autopaginate template tag already sets the invalid_page context variable.
The
problem is that the paginate template tag doesn't check for it, and so the 500
error
occurs in that function (when trying to access paginator and page_obj) before
you
ever get into the pagination template.
The problem with the invalid_page solution is that it leaves you with only one
realistic option of how to "gracefully handle" an invalid page: display an error
message. Options like using page 1 as the default (as I prefer) or raising a
404 are
not possible to do from a template without ugly hackery. Both of these would be
trivial to do in code within the autopaginate tag, if either a setting or
arguments
to the template tag were available to select the preferred option.
Original comment by carl.j.meyer
on 7 Nov 2008 at 8:22
Original comment by flo...@gmail.com
on 29 Nov 2008 at 5:46
Fixed in r45
Original comment by flo...@gmail.com
on 4 Dec 2008 at 9:49
I believe that raising an exception on the template tag render method is against
Django policy:
" (..) render() should never raise TemplateSyntaxError or any other exception.
It
should fail silently, just as template filters should. "
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-the-ren
derer
I suggest deprecating the PAGINATION_INVALID_PAGE_RAISES_404 option. The
autopaginate
template fails silently, but sets a flag on the request indicating the problem.
After
the template is rendered, the pagination middleware checks this flag and
decides what
to do. Enter the PAGINATION_INVALID_PAGE_RESPONSE option.
* If PAGINATION_INVALID_PAGE_RESPONSE = '404', the middleware returns a 404 page.
* If PAGINATION_INVALID_PAGE_RESPONSE = '302', it returns a 302 redirection to the
same view, first page.
* Otherwise it returns the rendered template.
I've attached a small patch for SVN revision r50 with this logic.
Original comment by rvio...@gmail.com
on 29 Nov 2009 at 1:53
Attachments:
Original issue reported on code.google.com by
carl.j.meyer
on 6 Nov 2008 at 4:27