📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials Flask Web Framework Flask Pagination

Flask Pagination

4 min read
Paginate SQLAlchemy queries with .paginate() and access items, total, pages, and navigation.

Pagination

@app.route("/posts")
def posts():
    page = request.args.get("page", 1, type=int)
    pagination = Post.query.order_by(Post.created_at.desc()).paginate(
        page=page, per_page=10, error_out=False
    )
    return render_template("posts.html",
        posts=pagination.items,
        pagination=pagination,
        total=pagination.total
    )