def get_page(self, data):
try:
page_no = int(self.request.GET.get(self.page_attribute_name, 1))
except (TypeError, ValueError):
raise NotFound('Invalid page number.')
if page_no < 1:
raise NotFound('Page number should be 1 or greater.')
# Explicitly evaluate data before sending it to Paginator, otherwise
# (at least in the case of RelatedSearchQuerySet) the total count
# goes completely wrong
# see: https://github.com/django-haystack/django-haystack/issues/362
data[:self.results_per_page]
paginator = Paginator(data, self.results_per_page)
try:
page = paginator.page(page_no)
except InvalidPage:
raise NotFound('No such page!')
return page
评论列表
文章目录