I am using Flask-Bootstrap's render_pagination
macro. When I click the page numbers, it changes the URL to have page=2
, but when the page re-renders, the results and page are still for page 1. How do I change the page and results when using render_pagination
?
@app.route('/results')
def results(filename, page=1):
logs = Logs.query.paginate(page)
return render_template('results.html', logs=logs)
{% from "bootstrap/pagination.html" import render_pagination %}
{% for log in logs.items %}
{{ log }}
{% endfor %}
{{ render_pagination(logs) }}
Flask-Bootstrap only deals with the frontend, you need to implement pagination on the backend. It renders links to the current view while changing the
page
query arg. You need to access this arg fromrequest.args
in the view and use it when paginating your query, by passing it toquery.paginate
.