python flask实现分页效果

houzeyu 2017-06-27

在我们学习的过程中会遇到这么样的问题,就是在我们学习的过程中会发现需要分页处理,这里呢,给大家介绍书上说的分页。

@app.route('/',methods=['GET'])
@app.route('/<int:page>')
def home(page=1):
  pagination=Post.query.order_by(Post.publish_date.desc()).paginate(page, per_page=10,error_out=False)
  posts = pagination.items
  link,tuijian_post,fenlei=get_tui_link()
  return render_template('home1.html',
              posts=posts,
              pagination=pagination,
              tuijian_post=tuijian_post,fenleis=fenlei,        
              links=link)

这是我从数据库读取的分页的数据,那么我们怎么分页呢,我们看看书上怎么说

python flask实现分页效果

那么我们需要用一个单独页面取保存我们分页相关的,。

那么我们怎么使用呢

{% import "mac.html" as macros %}

在我们的循环后加入下面的

python flask实现分页效果

效果如图

python flask实现分页效果

相关推荐

yyyxxxs / 0评论 2020-05-10