首页 > 编程语言 > 详细

python-----Django自定义分页器

时间:2021-06-25 16:46:12      阅读:12      评论:0      收藏:0      [点我收藏+]

python-----Django自定义分页器

 def page_custom(self, objlist, currentpage=1, p_size=10):
        """
            自定义分页器
        """
        if not currentpage or int(currentpage) < 1:
            currentpage = 1
        current_page = int(currentpage)
        p_size = int(p_size)
        start = (current_page - 1) * p_size
        end = current_page * p_size
        data = objlist[start:end]
        total_count = len(objlist)
        total_page = len(objlist) // p_size
        remainder = len(objlist) % p_size
        if remainder and remainder < p_size:
            total_page += 1
        res = {
            "total_page": total_page,
            "page": current_page,
            "size": p_size,
            "total_count": total_count,
            "result": data
        }
        return res

python-----Django自定义分页器

原文:https://www.cnblogs.com/tjw-bk/p/14930688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!