zoukankan      html  css  js  c++  java
  • django 分页函数

    实现类似:

    上一页 1 ... 4 5 6 7 8 ... 89 下一页

    的效果

    def pageGenerate(fullList,pagenum,urltype,type,currpage):
        pageObj=Paginator(fullList,pagenum)
        totalPage=pageObj.num_pages
        pageitems=pageObj.page(currpage).object_list
        #上下页标签
        if pageObj.page(currpage).has_next():
            next_page=currpage+1
        else:
            next_page=0
        if pageObj.page(currpage).has_previous():
            previous_page=currpage-1
        else:
            previous_page=0
    
        #数字页,前后各2页
        pageresult=[]
        link={-2:currpage-2,-1:currpage-1,0:currpage,1:totalPage-currpage-1,2:totalPage-currpage-2}
        for k,v in link.items():
            if v>0:
                pageresult.append(currpage+k)
    
        if pageresult[0]==2:
            pageresult=[1]+pageresult
        elif pageresult[0]>2:
            pageresult=[1,0]+pageresult
        if pageresult[len(pageresult)-1]+1==totalPage:
            pageresult=pageresult+[totalPage]
        elif pageresult[len(pageresult)-1]+1<totalPage:
            pageresult = pageresult + [0,totalPage]
    
        pagerelease={'pageitems':pageitems,'urltype':urltype,'type':type,'currpage':currpage,'previous_page':previous_page,'pageresult':pageresult,'next_page':next_page}
        return pagerelease
    

      

  • 相关阅读:
    原型链
    原型规则总结
    使用typeof能得到的哪些类型
    eslint 规则中文注释
    两张图片互相切换
    输入框获得焦点与失去焦点、阴影效果
    vue 写table的几种方式
    vue 注意事项
    angular 接口定义封装
    @NgModule
  • 原文地址:https://www.cnblogs.com/pythonClub/p/9824359.html
Copyright © 2011-2022 走看看