码迷,mamicode.com
首页 > 其他好文 > 详细

自定义分页器

时间:2019-08-18 13:44:59      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:sel   pen   git   init   自定义   int   stop   def   ota   

class PageInfo:
    def __init__(self, num_page, total, uri, pei_page=10, show_page=11):
        if num_page.isdigit():
            num_page = int(num_page)
        else:
            num_page = 1
        self.num_page = num_page
        self.pei_page = pei_page
        self.show_page = show_page
        self.uri = uri
        a, b = divmod(total, pei_page)
        self.total_page = a
        if b:
            self.total_page += 1

    def get_start(self):
        return (self.num_page - 1) * 10

    def get_stop(self):
        return self.num_page * 10

    def page(self):
        args = []
        if self.num_page - (self.show_page // 2) < 1:
            start = 1
            end = self.show_page + 1
        elif self.num_page + (self.show_page // 2) > self.total_page:
            start = self.total_page - self.show_page
            end = self.total_page + 1
        else:
            start = self.num_page - (self.show_page // 2)
            end = self.num_page + (self.show_page // 2) + 1
            print(end)
        if self.num_page - 1 > 0:
            s = "<li><a href=‘/%s%s‘>上一页</a></li>" % (self.uri, self.num_page - 1)
        else:
            s = "<li class=‘disabled‘><a href=‘#‘ >上一页</a></li>"
        args.append(s)
        for i in range(start, end):
            if i == self.num_page:
                s = "<li class=‘active‘><a href=‘/%s%s‘>%s </a></li>" % (self.uri, i, i)
            else:
                s = "<li><a href=‘/%s%s‘>%s </a></li>" % (self.uri, i, i)
            args.append(s)
        if self.num_page + 1 > self.total_page:
            s = "<li class=‘disabled‘><a href=‘#‘ >下一页</a></li>"
        else:
            s = "<li><a href=‘/%s%s‘ >下一页</a></li>" % (self.uri, self.num_page + 1)
        args.append(s)
        return "".join(args)

 

自定义分页器

标签:sel   pen   git   init   自定义   int   stop   def   ota   

原文地址:https://www.cnblogs.com/jixu/p/11371880.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!