resources.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:restless-haystack 作者: CraveFood 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号