Pagination support for flask

Related tags

Flaskflaskpaginate
Overview

flask-paginate

Pagination support for flask framework (study from will_paginate). It supports several css frameworks. It requires Python2.6+ as string.format syntax.

If you want to show pagination-info ("Total 100 posts, displaying 20 - 30") above the pagination links, please add the below lines to your css file::

.. sourcecode:: css

.pagination-page-info {
    padding: .6em;
    padding-left: 0;
    width: 40em;
    margin: .5em;
    margin-left: 0;
    font-size: 12px;
}
.pagination-page-info b {
    color: black;
    background: #6aa6ed;
    padding-left: 2px;
    padding: .1em .25em;
    font-size: 150%;
}

Full documentation: http://flask-paginate.readthedocs.io

Run example:

$cd example
$python sql.py
$python sql.py init_db
$python sql.py fill_data --total=310
$cp app.cfg.example app.cfg
$echo edit app.cfg
$python app.py --port 5000

Open http://localhost:5000 to see the example page.

demo

Comments
  • UndefinedError: 'flask_paginate.Pagination object' has no attribute 'skip'

    UndefinedError: 'flask_paginate.Pagination object' has no attribute 'skip'

    网页加上这句话会报错

    {{ loop.index + paginate.skip }} 后台代码如下

    def index(): search = False q = request.args.get('q') if q: search = True

    page = request.args.get(get_page_parameter(), type=int, default=1)
    per_page = int(request.args.get('per_page', 2))
    
    print(page,per_page)
    selectdata = User.query.filter_by(password='123456').all()
    
    
    
    paginate = Pagination(page=1, total=len(selectdata), search=search, record_name='users',per_page= per_page,per_page_parameter = 'per_page')
    #paginate = selectdata.paginate(page, per_page, error_out=False)
    #stus = paginate.items
    
    return render_template('index.html',
                           stus=selectdata,
                           paginate=paginate,
                           )
    
    opened by zht3344 11
  • HTML Escaping of Links

    HTML Escaping of Links

    In my view template, I render links like this:

    {{ pagination.links|safe }}

    However, this is how they appear:

    <a href="/blog%3Fpage%3D2">2</a>

    It appears the |safe filter isn't working, since the URL should be like this:

    <a href="/blog?page=2">2</a>

    Does anyone else have this issue? Python 3.4

    opened by pingometer 10
  • After setting page_parameter to anything else other than 'page', current page is not marked active

    After setting page_parameter to anything else other than 'page', current page is not marked active

    If you set page_parameter option to anything else other than the default ("page"), active breaks. In other words, suppose I set page_parameter to "p", no matter what page I'm on, the "active" class is always on page 1.

    I'm using bootstrap 3, but this happens with bootstrap 2 as well.

    opened by aldacron 9
  • Python 3.4 support

    Python 3.4 support

    I use python 3.4 and Flask 0.10.1 Pagination.links gets an exeption AttributeError: 'ImmutableMultiDict' object has no attribute 'iteritems' on this line: https://github.com/lixxu/flask-paginate/blob/master/flask_paginate/init.py#L207

    python args = MultiDict(list(request.args.iteritems(multi=True)) + request.view_args.items())

    
    This fork works well: https://github.com/nesforge/flask-paginate
    Patch: https://github.com/nesforge/flask-paginate/commit/6ea9b821e14e1a92884bf2ebd152cf400caa42e9
    
    opened by ak4nv 8
  • Added page_parameter

    Added page_parameter

    I added a new page_name_parameter that allows you to have a custom name for the page GET parameter, not just ?page=1 Use case: you can iterate over two(possibly more) paginator objects on a generated page simultaneously. page = int(request.args.get(page_parameter, 1) Paginator(page=page, page_parameter=page_parameter, **args)

    opened by voltterra 7
  • pagination links are not showing

    pagination links are not showing

    I have installed flask-paginate using $ pip install flask-paginate for my flask application and i have added css, html code as mentioned in this page

    am able to render the objects and and paginate.info but the links are not showing like bellow image

    paginate-links

    and my view is

    @app.route('/')
    def index():
    search = False
    q = request.args.get('q')
    if q:
        search = True
    
    users = Onboard.query.all()
    pagination = Pagination(users.count, search=search,total = 2, per_page=2, inner_window=2, outer_window=2, record_name='users')
    return render_template('index.html',
                           users=users,
                           pagination=pagination,
                           )
    
    <table><tr><td></td></tr></table>```
    

    can you please help to show the page links and if i click on that page i need to get respective objects how can i achieve this functionality I apologize for my bad English
    Thanks in advance

    opened by sunny527 7
  • pagination links are not showing

    pagination links are not showing

    flask-paginate 0.5.2

    my view:

    ....
            pagination = Pagination(bs_version=3, page=page, total=total, outer_window=0, inner_window=2, )
        context = {
            'banners': banners,
            'boards': boards,
            'posts': posts,
            'pagination': pagination,
            'current_board': board_id
        }
        return render_template('front/front_index.html', **context)
    

    my html template:

               <ul class="post-list-group">
                    {% for post in posts %}
                        <li>
                            <div class="author-avatar-group">
                                <img src="{{ post.author.avatar or url_for('static',filename='common/images/logo.png') }}"
                                     alt="">
                            </div>
                            <div class="post-info-group">
                                <p class="post-title">
                                    <a href="{{ url_for('front.post_detail',post_id=post.id) }}">{{ post.title }}</a>
                                    {% if post.essence %}
                                        <span class="label label-danger">精华帖</span>
                                    {% endif %}
                                </p>
                                <p class="post-info">
                                    <span>Author:{{ post.author.username }}</span>
                                    <span>Post Time:{{ post.create_time }}</span>
                                    <span>Comment:0</span>
                                    <span>Read:0</span>
                                </p>
                            </div>
                        </li>
                    {% endfor %}
                </ul>
                <div style="text-align: center">
                    {{ pagination.info }}
                    {{ pagination.links}}
                </div>
    

    image

    opened by Haitianisgood 6
  • Adding Additional querystring parameters

    Adding Additional querystring parameters

    Is it possible to add additional querystring parameters to the links generated by the plugin. I have some filtering parameters on the page that I'd like to send while loading the second page

    opened by ganeshran 6
  • Issue with paginate links and css

    Issue with paginate links and css

    Hello, Im using your great code, and it works great with the core function (pagination)

    Im only have a problem, with the pagination links: there is no way to use Bootstrap 4 styles. I'm getting a vertical list of links.

    I will appreciate you can help me

    Thanks.

    Sergio

    This is my code on Flask

    return render_template('usuarios/listusers.html', 
                title="Listado de Usuarios", datos = datos_filtrados, \
                pagination=pagination, bs_version='4', css_framework='bootstrap') 
    
    opened by sergiodevelop78 5
  • Won't play nice with URLs containing double quotes

    Won't play nice with URLs containing double quotes

    Pagination will break if the URL contain double quotes (ie. hrefs containing JSON strings).

    You should be fine using the url_for directly instead of unquotting it later with urllib in get_link.

    Replacing:

    return self.get_link(url_for(self.endpoint, page=page, **self.args))
    

    With:

    return url_for(self.endpoint, page=page, **self.args)
    

    Did the trick for me and should not affect other cases/scenarios.

    opened by afmacedo 5
  • Generating wrong url with parameter(s)

    Generating wrong url with parameter(s)

    I come into a problem that the page links are generated incorrectly when the paginated view has parameter(s). For example, my view has following definition:

    @route('/something/<param>') def something(param): ...

    and the generated url links are like this: http://xxxxxx/something/[u'param']?page=2

    This seems to be an issue of the args property, as it passes a MultiDict to url_for as kwargs which wrongly parses the param string into a list. I solved this by changing

    if PY2:
        args_items = request.args.iteritems(multi=True)
    else:
        args_items = request.args.items(multi=True)
    args = MultiDict(list(args_items) + list(request.view_args.items()))
    

    into

    args_items = request.args.items()
    args = dict(args_items + request.view_args.items())
    

    And everything works fine.

    Hope to solve this issue in new release.

    opened by wizcas 5
  • Implement Custom CSS Style

    Implement Custom CSS Style

    Hello!

    How would one go about adding a custom theme for the pagination (padding, transition etc) without having to modify the library? The currently available options aren't supporting a custom theme.

    Regards

    opened by void-pulsar 0
  • How add custom href for links?

    How add custom href for links?

    Hello. I don't understand, how add custom href for links for forms with post method. How use 'href'? I need to pass data from a POST request to other pages. How to do it better? Which meeans 'contain {0}'? Could you show examples?

    opened by anhazanov 1
  • paginate in bootstrap / prev, next btn class

    paginate in bootstrap / prev, next btn class

    image

    prev or next btn display is none....

    befor : <a class="page-link" href="#" aria-label="Next"><span aria-hidden="true">» </span> <span class="sr-only"> Next </span> </a> what i want <a class="page-item" href="#" aria-label="Next"><span aria-hidden="true" class="page-link">»</span><span class="sr-only">Next</span></a>

    Emitted when some classes are deleted or added. What's the problem?

    opened by HeoJinHo 3
  • Example: No such command 'init_db'

    Example: No such command 'init_db'

    Hi, is the example supposed to be self-contained (except of course for installing the necessary modules)?

    I have tried to follow the instructions, but it does not run for me as-is:

    (pagination_example) ➜  example git:(master) ✗ python sql.py
    Usage: sql.py [OPTIONS] COMMAND [ARGS]...
    
    Options:
      --help  Show this message and exit.
    
    Commands:
      fill-data  fill records to database
      init-db    initialize database and tables
    (pagination_example) ➜  example git:(master) ✗ python sql.py init_db
    Usage: sql.py [OPTIONS] COMMAND [ARGS]...
    Try 'sql.py --help' for help.
    
    Error: No such command 'init_db'.
    

    I'm sure this is some basic configuration issue that I happen not to be aware of, but some help would be appreciated.

    opened by jbhanks 3
  • Crash when pagination set to 0 (aka disabled pagination)

    Crash when pagination set to 0 (aka disabled pagination)

    Hi,

    If I set the pp=0 when creating a new Pagination instance, I've this error:

        p = Pagination(
      File "/home/xxx/prj/xxx/xxx/venv/lib/python3.8/site-packages/flask_paginate/__init__.py", line 403, in __init__
        self.init_values()
      File "/home/xxx/prj/xxx/xxx/venv/lib/python3.8/site-packages/flask_paginate/__init__.py", line 423, in init_values
        pages = divmod(current_total, self.per_page)
    ZeroDivisionError: integer division or modulo by zero
    

    Well, it seems data validation should be done inside the module (especially in a web context for obvious security reasons). Second point, when set to 0, it would be nice to completely disable the pagination (New feature).

    I'd be glad to do/help with the patch :)

    Cheers

    opened by mrjk 2
  • No pagination info update

    No pagination info update

    Hi, using search_msg and record_msg in Pagination.init() does not make the pagination update. also, what is the current state of this project ?

    Regards,

    opened by Remaetanju 0
Releases(v2022.1.8)
Owner
Lix Xu
他人笑我太疯癫, 我笑他人看不穿.
Lix Xu
Guitar tabs web app for guitar fans, powered by Python/Flask

Guitar123 version 0.8.5 Guitar tabs web app for guitar fans, powered by Python/Flask Features Guitar tabs search and browse Easy to use for end user a

lowrain 48 Dec 27, 2022
A gRpc server like Flask (像Flask一样的gRpc服务)

Mask A gRpc server just like Flask. Install Mask support pypi packages, you can simply install by: pip install mask Document Mask manual could be fou

吴东 16 Jun 14, 2022
Full-Stack application that visualizes amusement park safety.

Amusement Park Ride Safety Analysis Project Proposal We have chosen to look into amusement park data to explore ride safety relationships visually, in

Michael Absher 0 Jul 11, 2021
A swagger 2.0 spec extractor for flask

flask-swagger A Swagger 2.0 spec extractor for Flask You can now specify base path for yml files: app = Flask(__name__) @app.route("/spec") def spec(

Sling 457 Dec 02, 2022
Flask extension for Pusher

Flask-Pusher Flask extension for Pusher. It is a thin wrapper around the official client, binding Flask app to Pusher client. Installation Install Fla

Iuri de Silvio 9 May 29, 2021
Free casino website. Madden just for learning / fun

Website Casino Free casino website. Madden just for learning / fun. Uses Jinja2 (HTML), Flask, JavaScript, etc. Dice game Preview

Kirill Zhosul 0 Jun 22, 2022
Map Matching & Weight Completion service - Java (Springboot) & Python(Flask)

Map Matching service to match coordinates to roads using Java and Springboot. Weight Completion service to fill in missing weights in a graph, using Python and Flask.

2 May 13, 2022
Track requests to your Flask website with Matomo

Flask-Matomo Flask-Matomo is a library which lets you track the requests of your Flask website using Matomo (Piwik). Installation pip install flask-ma

Lucas Hild 13 Jul 14, 2022
Pf-flask-rest-com - Flask REST API Common Implementation by Problem Fighter Library

In the name of God, the Most Gracious, the Most Merciful. PF-Flask-Rest-Com Docu

Problem Fighter 3 Jan 15, 2022
OpenTracing instrumentation for the Flask microframework

Flask-OpenTracing This package enables distributed tracing in Flask applications via The OpenTracing Project. Once a production system contends with r

3rd-Party OpenTracing API Contributions 133 Dec 19, 2022
A Fast API style support for Flask. Gives you MyPy types with the flexibility of flask

Flask-Fastx Flask-Fastx is a Fast API style support for Flask. It Gives you MyPy types with the flexibility of flask. Compatibility Flask-Fastx requir

Tactful.ai 18 Nov 26, 2022
SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF).

Flask-SeaSurf SeaSurf is a Flask extension for preventing cross-site request forgery (CSRF). CSRF vulnerabilities have been found in large and popular

Max Countryman 183 Dec 28, 2022
A service made with Flask and Python to help you find the weather of your favorite cities.

Weather-App A service made with Flask and Python to help you find the weather of your favorite cities. Features Backend using Flask and Jinja Weather

Cauã Rinaldi 1 Nov 17, 2022
A simple FastAPI web service + Vue.js based UI over a rclip-style clip embedding database.

Explore CLIP Embeddings in a rclip database A simple FastAPI web service + Vue.js based UI over a rclip-style clip embedding database. A live demo of

18 Oct 15, 2022
Basic flask system for login, api, and status system

Flask Multi Site With Login This is a basic website login system with an uncomplete api system NOTICE : This is NOT complete and is made to be a bare

MrShoe 0 Feb 02, 2022
RestApi_flask_sql.alchemy - Product REST API With Flask & SQL Alchemy

REST API With Flask & SQL Alchemy Products API using Python Flask, SQL Alchemy and Marshmallow Quick Start Using Pipenv # Activate venv $ pipenv shell

amirwahla 1 Jan 01, 2022
A simple application builder. Made with python.

Python Flask Server Template Check the Github Repository for updates Flask is an application builder. It is very common in Python but can also be used

1 Jan 09, 2022
Burp-UI is a web-ui for burp backup written in python with Flask and jQuery/Bootstrap

Burp-UI Contents Introduction Screenshots Demo What's that? Who are you? Documentation FAQ Community Notes See also Licenses Thanks Introduction Scree

Benjamin 84 Dec 20, 2022
Python Flask API service, backed by DynamoDB, running on AWS Lambda using the traditional Serverless Framework.

Serverless Framework Python Flask API service backed by DynamoDB on AWS Python Flask API service, backed by DynamoDB, running on AWS Lambda using the

Andreu Jové 0 Apr 17, 2022
Flask RESTful Web services using API to communicate between client and server.

Welcome! Open up two terminals, one for client and for server each Terminal 1 Terminal 2 Now navigate to the CW2_code directory in both like so $ cd C

Sehra Elahi 1 Nov 23, 2021