1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | def paginate(request, objects, count=10, param_name='page'):
"""
Shortcut for paginating by some object
"""
paginator = Paginator(objects, count)
try:
pagenum = int(request.GET.get('%s' % param_name, '1'))
except ValueError:
pagenum = 1
try:
result = paginator.page(pagenum)
except (EmptyPage, InvalidPage):
result = paginator.page(paginator.num_pages)
return result
|
More like this
- Extend generic view object_list to support paginate_by via cookies by kersurk 2 years, 4 months ago
- Lazily lookup dynamically for templates by axiak 5 years, 2 months ago
- GlobalRequest middleware by myq 5 months, 4 weeks ago
- Paginator Tag for 1.x by HM 4 years, 2 months ago
- Other approach of making middleware (by decorators) by diverman 2 years, 2 months ago
Comments