Comments (9)
pagination = Pagination(p=5,
per_page=10,
total=1000,
page_parameter='p',
css_framework='bootstrap4')
when you set page_parameter
to p
, you also need to set p=5
instead of page=5
.
from flask-paginate.
What are the parameters to the Pagination
?
from flask-paginate.
Sorry, it wasn't clear to me that I had to change "page" to "p" since I changed it in page_parameter. Would appreciate if this got documented!
from flask-paginate.
This was also very confusing for me and should definetly be better described in the docs. For others having the problem: Instead of the page
argument name, this argument name has to be the same as the value you pass to page_parameter
.
Since I have multiple Paginators on the same page, I generate my pagination ids automatically. So now I end up with something like this:
pagination_id = generate_pagination_id() # ... generated somehow
page, per_page, offset = get_page_args_with_param(pagination_id)
pagination = Pagination(total=total_items,
page_parameter=pagination_id,
**{pagination_id: page})
Also I needed to customize get_page_args
a bit:
# slightly modified version of flask_paginate.get_page_args to support the `param` argument
def get_page_args_with_param(param='page'):
args = request.args.copy()
args.update(request.view_args.copy())
page_parameter = args.get('page_parameter', param)
page = int(args.get(page_parameter, 1))
per_page = args.get('per_page')
if not per_page:
per_page = current_app.config.get('PER_PAGE', 10)
else:
per_page = int(per_page)
offset = (page - 1) * per_page
return page, per_page, offset
from flask-paginate.
I update it to version 0.5.0 which can customize page_parameter
and per_page_parameter
, please try.
from flask-paginate.
close as long time pending.
from flask-paginate.
Hi @lixxu, can we reopen this issue? I think the issue might still exist.
To reproduce, you can hardcode the following Pagination object:
pagination = Pagination(page=5,
per_page=10,
total=1000,
page_parameter='p',
css_framework='bootstrap4')
Going to route with &p=5
ignores the active page, says that it is displaying 1 - 10 records in total 1000
and marks page 1 as active.
When changing back to:
pagination = Pagination(page=5,
per_page=10,
total=1000,
page_parameter='page',
css_framework='bootstrap4')
it correctly displays pagination with displaying 41 - 50 records in total 1000
and page 5 as active.
from flask-paginate.
@lixxu I found the problem causing this:
Pagination object is initialized and self.page
takes a kwarg equal to self.page_parameter
:
flask-paginate/flask_paginate/__init__.py
Line 313 in 6445a67
So, if page_parameter="p"
, Pagination will ignore page=5
kwarg and look for p=5
.
Changing that line to:
self.page = kwargs.get("page", 1)
solves the problem. Happy to do a PR if you'd like.
from flask-paginate.
@lixxu, yes, thank you. Personally I found it pretty confusing, but if you would like to keep this behavior, I would be happy to make a PR to update docs making this more clear.
from flask-paginate.
Related Issues (20)
- [Regression] AttributeError: 'Pagination' object has no attribute 'bs_version' HOT 2
- Paginate shows all results on the same page. HOT 2
- How add custom href for links? HOT 1
- Implement Custom CSS Style
- Adding pagination breaks dynamic update of checkbox status HOT 1
- Page # in pagination blocks stays at 1 when two pagination blocks are used HOT 2
- css_framework='boostrap3' or css_framework=''bootsrap4' or css_framework='bootstrap' and bs_version=4 not working HOT 2
- flask >= 3, from flask import Markup broken HOT 4
- Missing rel attributes for links HOT 5
- did't show pagination.links HOT 1
- Please add an init parameter to control the url generation behavior for page 1 and prev_page HOT 4
- quote url value of href attribute for bulma css HOT 2
- There is an error in "app.cfg.example" where there is a missing "sign" after records. HOT 1
- Example: No such command 'init_db' HOT 3
- Translate text shown in {{ pagination.info }} HOT 2
- paginate in bootstrap / prev, next btn class HOT 3
- Missing tag for 2021.10.29 release HOT 1
- Does it only work for python Sql module? HOT 2
- TestPagination.test_defaults fails HOT 2
- Missing tag for 2021.12.28 release HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flask-paginate.