On Wed, Jan 4, 2012 at 12:09 PM, Matt Stevens <m...@everystyle.co.uk> wrote:
> I've found a solution, but I don't like it.

The canonical solution is included in the docs:

https://docs.djangoproject.com/en/1.3/topics/pagination/#using-paginator-in-a-view

Briefly:


  paginator = Paginator(objects, 50, orphans=10)

  # Make sure page request is an int. If not, deliver first page.
  try:
    page = int(request.GET.get('page', '1'))
  except ValueError:
    page = 1

  # If page request (9999) is out of range, deliver last page of results.
  try:
    objects = paginator.page(page)
  except (EmptyPage, InvalidPage):
    objects = paginator.page(paginator.num_pages)

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to