• 分页操作使用


    1. 导入分页模块

    try:

      page = int(request.args.get(‘p’,1))

    except:

    page=1

    page_count = 10

    userpag = User.query.paginate(page,page_count,False)

    userlist = userpag.items     #一共多少条

    total_page = userpag.pages  #当前有多少页

    current_page = userpag.page    #当前多少页

    1. 页面用jquery

     

    <link rel="stylesheet" href="/static/sadmin/css/jquery.pagination.css">

        <script type="text/javascript" src="/static/sadmin/js/jquery-1.12.4.min.js"></script>

        <script type="text/javascript" src="/static/sadmin/js/jquery.pagination.min.js"></script>

     

     

    $("#pagination").pagination({

                        currentPage: {{current_page}},

                        totalPage: {{total_page}},

                        callback: function(current) {

                            var keyword = $(".input_txt").val()

                            window.location.href="/sadmin/goodslist/?p="+current+"&keyword="+keyword

                        }

                    });

     

     

    @web_blue.route('/fenye')
    def hellw():
        PER_PAGE = 10
        total = Fen.query.count()
        print(total)
        page = request.args.get(get_page_parameter(),type=int,default=1)
        start = (page-1)*PER_PAGE
        end = start + PER_PAGE
        pagination = Pagination(bs_version=3,page=page,total=total)
        articles = Fen.query.slice(start,end)
        context = {
            'pagination':pagination,
            'articles':articles
        }
        return render_template('index.html',**context)

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
    {% for a in articles %}
        <ul>
            <li>{{ a.name }}</li>
        </ul>
    {% endfor %}
    {{ pagination.links }}

    展详

    @web_blue.route('/webgood',methods=['post','get'])

    def webgood():

    try:

    id = int(request.args.get('id'))

    except:

    id = 0

    good = ''

    if id >0:

    good = Good.query.filter(Good.id == id).first()

    cate = Cate.query.all()

    return render_template("web/webgood.html",cate=cate,good=good)

    展首展首

  • 相关阅读:
    遗产继承骗局
    Nginx配置https和wss
    Servlet乱码问题
    logback+slf4j作为日志系统
    InteliJ Idea通过maven创建webapp
    pip安装注意事项
    [转]TCP(HTTP)长连接和短连接区别和怎样维护长连接
    Python Socket编程初探
    有用的git片段
    Python使用chardet包自动检测编码
  • 原文地址:https://www.cnblogs.com/zuichuyouren/p/11094670.html
Copyright © 2020-2023  润新知