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 comprehensive CRUD API generator for SQLALchemy.

FastAPI Quick CRUD Introduction Advantage Constraint Getting started Installation Usage Design Path Parameter Query Parameter Request Body Upsert Intr

192 Jan 06, 2023
Beyonic API Python official client library simplified examples using Flask, Django and Fast API.

Beyonic API Python Examples. The beyonic APIs Doc Reference: https://apidocs.beyonic.com/ To start using the Beyonic API Python API, you need to start

Harun Mbaabu Mwenda 46 Sep 01, 2022
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
Toolkit for developing and maintaining ML models

modelkit Python framework for production ML systems. modelkit is a minimalist yet powerful MLOps library for Python, built for people who want to depl

140 Dec 27, 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
Reusable utilities for FastAPI

Reusable utilities for FastAPI Documentation: https://fastapi-utils.davidmontague.xyz Source Code: https://github.com/dmontagu/fastapi-utils FastAPI i

David Montague 1.3k Jan 04, 2023
Simple notes app backend using Python's FastAPI framework.

my-notes-app Simple notes app backend using Python's FastAPI framework. Route "/": User login (GET): return 200, list of all of their notes; User sign

José Gabriel Mourão Bezerra 2 Sep 17, 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
Prometheus exporter for several chia node statistics

prometheus-chia-exporter Prometheus exporter for several chia node statistics It's assumed that the full node, the harvester and the wallet run on the

30 Sep 19, 2022
Sample project showing reliable data ingestion application using FastAPI and dramatiq

Create and deploy a reliable data ingestion service with FastAPI, SQLModel and Dramatiq This is the source code for the data ingestion service explain

François Voron 31 Nov 30, 2022
FastAPI Skeleton App to serve machine learning models production-ready.

FastAPI Model Server Skeleton Serving machine learning models production-ready, fast, easy and secure powered by the great FastAPI by Sebastián Ramíre

268 Jan 01, 2023
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 minimal FastAPI implementation for Django !

Caution!!! This project is in early developing stage. So use it at you own risk. Bug reports / Fix PRs are welcomed. Installation pip install django-m

toki 23 Dec 24, 2022
OpenAPI for Todolist RESTful API

swagger-client OpenAPI for Todolist RESTful API This Python package is automatically generated by the Swagger Codegen project: API version: 1 Package

Iko Afianando 1 Dec 19, 2021
FastAPI-PostgreSQL-Celery-RabbitMQ-Redis bakcend with Docker containerization

FastAPI - PostgreSQL - Celery - Rabbitmq backend This source code implements the following architecture: All the required database endpoints are imple

Juan Esteban Aristizabal 54 Nov 26, 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
A rate limiter for Starlette and FastAPI

SlowApi A rate limiting library for Starlette and FastAPI adapted from flask-limiter. Note: this is alpha quality code still, the API may change, and

Laurent Savaete 562 Jan 01, 2023
Generate Class & Decorators for your FastAPI project ✨🚀

Classes and Decorators to use FastAPI with class based routing. In particular this allows you to construct an instance of a class and have methods of that instance be route handlers for FastAPI & Pyt

Yasser Tahiri 34 Oct 27, 2022
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
FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.

简体中文 | English 项目介绍 FastAPI-Amis-Admin fastapi-amis-admin是一个拥有高性能,高效率,易拓展的fastapi管理后台框架. 启发自Django-Admin,并且拥有不逊色于Django-Admin的强大功能. 源码 · 在线演示 · 文档 · 文

AmisAdmin 318 Dec 31, 2022