首页 > 解决方案 > Flask:使用flask-sqlalchermy分页结果错误

问题描述

我的代码是这样的:</p>

page = db.session.query(agent).filter(...).order_by(agent.create_time).paginate(1, 10)

结果是:page.total 为 9。

但是当我把代码改成这样的时候:</p>

page = db.session.query(agent).filter(...).order_by(agent.create_time).paginate(1, 20)

结果是:page.total 为 19。


在数据库终端执行sql的结果是19

我应该怎么办?

标签: pythonsqlalchemy

解决方案


If the query wasn't wrong, show the filter conditions.

The total is the result:

db.session.query(agent).filter(...).order_by(None).count()

total has nothing to do with page/per_page.


推荐阅读