Giter VIP home page Giter VIP logo

Comments (10)

lixxu avatar lixxu commented on May 27, 2024

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.

pingometer avatar pingometer commented on May 27, 2024

This is the output of pagination.links:

<ul class="pagination"><li class="previous disabled unavailable"><a href="#"> &laquo; </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">&raquo;</a></li></ul>

from flask-paginate.

lixxu avatar lixxu commented on May 27, 2024

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">&laquo;</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">&raquo;</a></li></ul>

What's your code look like?

from flask-paginate.

pingometer avatar pingometer commented on May 27, 2024

Here is what I get:

<ul class="pagination pagination-sm"><li class="previous disabled unavailable"><a href="#"> &laquo; </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">&raquo;</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.

lixxu avatar lixxu commented on May 27, 2024

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.

pingometer avatar pingometer commented on May 27, 2024

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:

screen shot 2014-10-23 at 4 34 08 pm

Link (pagination at the bottom): https://pingometer.com/blog

from flask-paginate.

lixxu avatar lixxu commented on May 27, 2024

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.

pingometer avatar pingometer commented on May 27, 2024

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.

lixxu avatar lixxu commented on May 27, 2024

add the python2 and python3 detect for urllib, please try new version 0.2.7

from flask-paginate.

pingometer avatar pingometer commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.