python分页的得得

2021-06-09 00:03

阅读:395

标签:使用   out   ==   count   lse   int   ges   try   turn   

charger_area_list, _ = cls.paginator(charger_area_list, page_no, page_size)

要定义类方法,才可以使用cls调用

class BaseService(object):

    @classmethod #  limit分页
    def limit_data(cls, all_list, page_no, page_size=10):
        limit_data, total_count = limit_page(all_list, page_no, page_size)
        return limit_data, total_count

    @classmethod
    def paginator(cls, data, page_no, page_size=10):
        paginator = Paginator(data, page_size)
        try:
            data_list = paginator.page(page_no)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            data_list = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver empty list
            data_list = []

        return data_list, paginator.num_pages

limit分页方法

def limit_page(data, page_no=1, page_size=10):
    """分页"""
    list_len = len(data)
    page_no = int(page_no)
    page_size = int(page_size)

    total_page = get_total_page(list_len, page_size)

    if page_no > total_page:
        return None, total_page

    if page_no 

python分页的得得

标签:使用   out   ==   count   lse   int   ges   try   turn   

原文地址:https://www.cnblogs.com/bkgeng/p/14506789.html


评论


亲,登录后才可以留言!