Comments (10)
Can you print pagination.links from your views to see if it's pagination problem or the safe issue, or flask on Python3.4 problem? This is works on Python2.7 on my project.
from flask-paginate.
This is the output of pagination.links
:
<ul class="pagination"><li class="previous disabled unavailable"><a href="#"> « </a></li><li class="active"><a href="#">1</a></li><li><a href="/blog%3Fpage%3D2">2</a></li><li class="next"><a href="/blog%3Fpage%3D2">»</a></li></ul>
from flask-paginate.
Can you try the example code and print to see the output? I tried and the output is:
<ul class="pagination pagination-sm"><li class="previous"><a href="/?page=3">«</a></li><li><a href="/">1</a></li><li><a href="/?page=2">2</a></li><li><a href="/?page=3">3</a></li><li class="active"><a href="#">4</a></li><li><a href="/?page=5">5</a></li><li><a href="/?page=6">6</a></li><li class="disabled"><a href="#">...</a></li><li><a href="/?page=20">20</a></li><li><a href="/?page=21">21</a></li><li class="next"><a href="/?page=5">»</a></li></ul>
What's your code look like?
from flask-paginate.
Here is what I get:
<ul class="pagination pagination-sm"><li class="previous disabled unavailable"><a href="#"> « </a></li><li class="active"><a href="#">1</a></li><li><a href="/?page=2">2</a></li><li><a href="/?page=3">3</a></li><li><a href="/?page=4">4</a></li><li><a href="/?page=5">5</a></li><li class="disabled"><a href="#">...</a></li><li><a href="/?page=30">30</a></li><li><a href="/?page=31">31</a></li><li class="next"><a href="/?page=2">»</a></li></ul>
It looks correct to me.
Here is my view function:
@app.route('/blog', defaults={'page': 1})
@app.route('/blog?page=int:page')
def posts(page):
posts = [p for p in flatpages if p.path.startswith(app.config['POST_DIR']) and p['date'] <= datetime.date.today().strftime('%B %-d, %Y')]
posts.sort(key=lambda item:item['date'], reverse=True)
sub_posts = posts[(page_5)-5:page_5]
pagination = Pagination(page=page, total=len(posts), record_name='posts', bs_version=3, per_page=5)
return render_template('posts.html', posts=sub_posts, pagination=pagination)
Anything jump out there?
from flask-paginate.
This line should be like this: @app.route('/blog?page=int:page'), and checkout the 0.2.6. I tried and it works.
Please comment if it can help you.
from flask-paginate.
I had <
and >
around "int:page" -- it looks like GitHub removed it in the comments for both of us.
It looks like this: @app.route('/blog?page=<int:page>')
So, it isn't related to that. Any ideas?
Also, if I upgrade to 0.2.6, the Pagination object is available, but calling links
on it returns nothing. Strange...
Screenshot of the exact code:
Link (pagination at the bottom): https://pingometer.com/blog
from flask-paginate.
I don't know why the page always 1.
Could you try this?
@app.route('/blog', defaults={'page': 1})
@app.route('/blog?page=<int:page>')
def posts(page):
page2 = int(request.args.get('page', 1))
page3 = int(request.view_args.get('page', 1))
print(page, page2, page3)
page = max((page, page2, page3))
from flask-paginate.
I found the problem (with the link encoding):
If I use 0.2.4 and return pagination.links
, I get the encoded links.
If I use 0.2.6 and return pagination.links
, I get this error:
AttributeError: 'module' object has no attribute 'unquote'
I found this StackOverflow post:
http://stackoverflow.com/questions/8628152/url-decode-with-python-3
The fix:
[FIND]
return urllib.unquote(url)
[REPLACE]
return urllib.parse.unquote(url)
Now, URLs are perfect in Python 3.4 w/ flask-paginate 0.2.6.
But, I still have the issue where the "page" is always 1
.
You can try here:
https://pingometer.com/blogtest?page=2
from flask-paginate.
add the python2 and python3 detect for urllib, please try new version 0.2.7
from flask-paginate.
Perfect!
I was able to fix the issue with page
defaulting to 1
-- routing issue.
Evidently, in Flask 0.10.1 and later, you can't define multiple routes for a single view function.
Instead, I use syntax like this:
@app.route('/blog')
def posts():
page = request.args.get('page', default=1, type=int)
...
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.