分页操作使用
Posted zuichuyouren
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了分页操作使用相关的知识,希望对你有一定的参考价值。
- 导入分页模块
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 #当前多少页
- 页面用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)
展首展首
以上是关于分页操作使用的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot整合mybatis使用pageHelper插件进行分页操作
MongoDB使用: 条件操作,排序,索引,分页查询,聚合函数