Pagination support for flask

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
A web application using [FastAPI + streamlit + Docker] Neural Style Transfer (NST) refers to a class of software algorithms that manipulate digital images

Neural Style Transfer Web App - [FastAPI + streamlit + Docker] NST - application based on the Perceptual Losses for Real-Time Style Transfer and Super

Roman Spiridonov 3 Dec 05, 2022
LuSyringe is a documentation injection tool for your classes when using Fast API

LuSyringe LuSyringe is a documentation injection tool for your classes when using Fast API Benefits The main benefit is being able to separate your bu

Enzo Ferrari 2 Sep 06, 2021
Keycloack plugin for FastApi.

FastAPI Keycloack Keycloack plugin for FastApi. Your aplication receives the claims decoded from the access token. Usage Run keycloak on port 8080 and

Elber 4 Jun 24, 2022
FastAPI interesting concepts.

fastapi_related_stuffs FastAPI interesting concepts. FastAPI version :- 0.70 Python3 version :- 3.9.x Steps Test Django Like settings export FASTAPI_S

Mohd Mujtaba 3 Feb 06, 2022
FastAPI IPyKernel Sandbox

FastAPI IPyKernel Sandbox This repository is a light-weight FastAPI project that is meant to provide a wrapper around IPyKernel interactions. It is in

Nick Wold 2 Oct 25, 2021
REST API with FastAPI and PostgreSQL

REST API with FastAPI and PostgreSQL To have the same data in db: create table CLIENT_DATA (id SERIAL PRIMARY KEY, fullname VARCHAR(50) NOT NULL,email

Luis Quiñones Requelme 1 Nov 11, 2021
🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞

Debug Toolbar 🐞 A debug toolbar for FastAPI based on the original django-debug-toolbar. 🐞 Swagger UI & GraphQL are supported. Documentation: https:/

Dani 74 Dec 30, 2022
This repository contains learning resources for Python Fast API Framework and Docker

This repository contains learning resources for Python Fast API Framework and Docker, Build High Performing Apps With Python BootCamp by Lux Academy and Data Science East Africa.

Harun Mbaabu Mwenda 23 Nov 20, 2022
Utils for fastapi based services.

Installation pip install fastapi-serviceutils Usage For more details and usage see: readthedocs Development Getting started After cloning the repo

Simon Kallfass 31 Nov 25, 2022
api versioning for fastapi web applications

fastapi-versioning api versioning for fastapi web applications Installation pip install fastapi-versioning Examples from fastapi import FastAPI from f

Dean Way 472 Jan 02, 2023
A request rate limiter for fastapi

fastapi-limiter Introduction FastAPI-Limiter is a rate limiting tool for fastapi routes. Requirements redis Install Just install from pypi pip insta

long2ice 200 Jan 08, 2023
🚀 Cookiecutter Template for FastAPI + React Projects. Using PostgreSQL, SQLAlchemy, and Docker

FastAPI + React · A cookiecutter template for bootstrapping a FastAPI and React project using a modern stack. Features FastAPI (Python 3.8) JWT authen

Gabriel Abud 1.4k Jan 02, 2023
Prometheus exporter for metrics from the MyAudi API

Prometheus Audi Exporter This Prometheus exporter exports metrics that it fetches from the MyAudi API. Usage Checkout submodules Install dependencies

Dieter Maes 7 Dec 19, 2022
A server hosts a FastAPI application and multiple clients can be connected to it via SocketIO.

FastAPI_and_SocketIO A server hosts a FastAPI application and multiple clients can be connected to it via SocketIO. Executing server.py sets up the se

Ankit Rana 2 Mar 04, 2022
Simple example of FastAPI + Celery + Triton for benchmarking

You can see the previous work from: https://github.com/Curt-Park/producer-consumer-fastapi-celery https://github.com/Curt-Park/triton-inference-server

Jinwoo Park (Curt) 37 Dec 29, 2022
Flask-vs-FastAPI - Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks.

Flask-vs-FastAPI Understanding Flask vs FastAPI Web Framework. A comparison of two different RestAPI frameworks. IntroductionIn Flask is a popular mic

Mithlesh Navlakhe 1 Jan 01, 2022
Browse JSON API in a HTML interface.

Falcon API Browse This project provides a middleware for Falcon Web Framework that will render the response in an HTML form for documentation purpose.

Abhilash Raj 4 Mar 16, 2022
A dynamic FastAPI router that automatically creates CRUD routes for your models

⚡ Create CRUD routes with lighting speed ⚡ A dynamic FastAPI router that automatically creates CRUD routes for your models Documentation: https://fast

Adam Watkins 943 Jan 01, 2023
Local Telegram Bot With FastAPI & Ngrok

An easy local telegram bot server with python, fastapi and ngrok.

Ömer Faruk Özdemir 7 Dec 25, 2022
A fast and durable Pub/Sub channel over Websockets. FastAPI + WebSockets + PubSub == ⚡ 💪 ❤️

⚡ 🗞️ FastAPI Websocket Pub/Sub A fast and durable Pub/Sub channel over Websockets. The easiest way to create a live publish / subscribe multi-cast ov

8 Dec 06, 2022