helpers.py 416 B

1234567891011121314
  1. from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
  2. def paginate(request, collection, per=12):
  3. paginator = Paginator(collection, per)
  4. page = request.GET.get('page')
  5. try:
  6. collection = paginator.page(page)
  7. except PageNotAnInteger:
  8. collection = paginator.page(1)
  9. except EmptyPage:
  10. collection = paginator.page(paginator.num_pages)
  11. return collection