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
Sample FastAPI project that uses async SQLAlchemy, SQLModel, Postgres, Alembic, and Docker.

FastAPI + SQLModel + Alembic Sample FastAPI project that uses async SQLAlchemy, SQLModel, Postgres, Alembic, and Docker. Want to learn how to build th

228 Jan 02, 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
FastAPI with Docker and Traefik

Dockerizing FastAPI with Postgres, Uvicorn, and Traefik Want to learn how to build this? Check out the post. Want to use this project? Development Bui

51 Jan 06, 2023
Flood Detection with Google Earth Engine

ee-fastapi: Flood Detection System A ee-fastapi is a simple FastAPI web application for performing flood detection using Google Earth Engine in the ba

Cesar Aybar 69 Jan 06, 2023
Generate modern Python clients from OpenAPI

openapi-python-client Generate modern Python clients from OpenAPI 3.x documents. This generator does not support OpenAPI 2.x FKA Swagger. If you need

Triax Technologies 558 Jan 07, 2023
A basic JSON-RPC implementation for your Flask-powered sites

Flask JSON-RPC A basic JSON-RPC implementation for your Flask-powered sites. Some reasons you might want to use: Simple, powerful, flexible and python

Cenobit Technologies 273 Dec 01, 2022
API for Submarino store

submarino-api API for the submarino e-commerce documentation read the documentation in: https://submarino-api.herokuapp.com/docs or in https://submari

Miguel 1 Oct 14, 2021
FastAPI Auth Starter Project

This is a template for FastAPI that comes with authentication preconfigured.

Oluwaseyifunmi Oyefeso 6 Nov 13, 2022
Easily integrate socket.io with your FastAPI app 🚀

fastapi-socketio Easly integrate socket.io with your FastAPI app. Installation Install this plugin using pip: $ pip install fastapi-socketio Usage To

Srdjan Stankovic 210 Dec 23, 2022
Cookiecutter template for FastAPI projects using: Machine Learning, Poetry, Azure Pipelines and Pytests

cookiecutter-fastapi In order to create a template to FastAPI projects. 🚀 Important To use this project you don't need fork it. Just run cookiecutter

Arthur Henrique 225 Dec 28, 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
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
MS Graph API authentication example with Fast API

MS Graph API authentication example with Fast API What it is & does This is a simple python service/webapp, using FastAPI with server side rendering,

Andrew Hart 4 Aug 11, 2022
A FastAPI WebSocket application that makes use of ncellapp package by @hemantapkh

ncellFastAPI author: @awebisam Used FastAPI to create WS application. Ncellapp module by @hemantapkh NOTE: Not following best practices and, needs ref

Aashish Bhandari 7 Oct 01, 2021
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
Dead simple CSRF security middleware for Starlette ⭐ and Fast API ⚡

csrf-starlette-fastapi Dead simple CSRF security middleware for Starlette ⭐ and Fast API ⚡ Will work with either a input type="hidden" field or ajax

Nathaniel Sabanski 9 Nov 20, 2022
Local Telegram Bot With FastAPI & Ngrok

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

Ömer Faruk Özdemir 7 Dec 25, 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
Keepalive - Discord Bot to keep threads from expiring

keepalive Discord Bot to keep threads from expiring Installation Create a new Di

Francesco Pierfederici 5 Mar 14, 2022
🍃 A comprehensive monitoring and alerting solution for the status of your Chia farmer and harvesters.

chia-monitor A monitoring tool to collect all important metrics from your Chia farming node and connected harvesters. It can send you push notificatio

Philipp Normann 153 Oct 21, 2022