近期项目需要制作一个数据分页查询,因为数据量较大,因此需要进行分页。
第一:关于分页样式,可以自行在网上去找,大把的模板,少量修改既可以。
第二:关于数据,本次项目使用的MongoDB,与MySQL或者Oracle查询语句是有区别的;
第三:python 配合Flask,确实很香。具体代码如下:
@app.route('/') # 定义路由(Views),可以理解为定义页面的URL
def index():
getsrc = request.args.get('src')
p = request.args.get('p')
if getsrc == None:
src = 'xxxxx'
else:
src = getsrc
show_status = 0
if not p:
p = 1
else:
p = int(p)
if p > 1:
show_status = 1
limit_start = (p-1)*10
result = db.fiancenews.find({'src':src}).sort([("published",-1)]).limit(10).skip(limit_start)
total = db.fiancenews.find({'src':src}).count()
page_total = int(math.ceil(total/10))
page_list = get_page(page_total, p)
datas = {
'data_list' : result,
'src' : src,
'p' : p,
'page_total' : page_total,
'show_status' : show_status,
'page_list' : page_list
}
return render_template('index.html', datas=datas)
Python一直学习中,代码写的非常不规范,欢迎评判与指正!
来源:CSDN
作者:哎呦喂小呆
链接:https://blog.csdn.net/qq_22085063/article/details/104297748