zoukankan      html  css  js  c++  java
  • 分页

    #!/usr/bin/env python
    # _*_ coding:utf-8 _*_
    from django.utils.safestring import mark_safe


    def Pager(page_count, current_page):
    html_dict = []
    first_page = '<a href="/hosts/1">首页</a>'
    html_dict.append(first_page)
    if current_page - 1 == 0:
    prev_page = '<a href="#">上一页</a>'
    else:
    prev_page = '<a href="/hosts/%s">上一页</a>' % (current_page - 1)
    html_dict.append(prev_page)
    if page_count < 12:
    start = 0
    end = page_count
    elif current_page - 6 <= 0:
    start = 0
    end = 11
    elif current_page + 5 >= page_count:
    start = page_count - 11
    end = page_count
    else:
    start = current_page - 6
    end = current_page + 5
    for i in range(start, end):
    if i + 1 == current_page:
    html = '<a href="/hosts/%s" class="selected">%s</a>' % ((i + 1), (i + 1))
    else:
    html = '<a href="/hosts/%s">%s</a>' % ((i + 1), (i + 1))
    html_dict.append(html)
    if current_page == page_count:
    last_page = '<a href="#">下一页</a>'
    else:
    last_page = '<a href="/hosts/%s">下一页</a>' % (current_page + 1)
    html_dict.append(last_page)

    end_page = '<a href="/hosts/%s">尾页</a>' % (page_count)
    html_dict.append(end_page)
    return mark_safe(''.join(html_dict))

  • 相关阅读:
    jQuery的基本使用、实践、效果、API
    关于Nginx那些事儿
    Linux下安装Nginx(保姆教程)
    jQuery的那些事儿
    k8s的应用回滚--record
    MySQL之PXC
    MySQL之高可用MHA
    MySQL之主从半同步复制
    MySQL之MyCat
    MySQL之主从复制
  • 原文地址:https://www.cnblogs.com/3one/p/5846182.html
Copyright © 2011-2022 走看看