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
Alexa Skills Kit for Python

Program the Amazon Echo with Python Flask-Ask is a Flask extension that makes building Alexa skills for the Amazon Echo easier and much more fun. Flas

John Wheeler 1.9k Dec 30, 2022
Harmony, a discord clone, allows users to chat with other users in real time via servers, channels, and direct messages

Harmony, a discord clone, allows users to chat with other users in real time via servers, channels, and direct messages

Seth Holland 3 Feb 03, 2022
An easy way to build your flask skeleton.

Flider What is Flider Flider is a lightweight framework that saves you time by creating a MVC compliant file structure and includes basic commonly use

Trevor Engen 8 Nov 17, 2022
a flask profiler which watches endpoint calls and tries to make some analysis.

Flask-profiler version: 1.8 Flask-profiler measures endpoints defined in your flask application; and provides you fine-grained report through a web in

Mustafa Atik 718 Dec 20, 2022
A solid foundation for your flask app

Flask Foundation There is a cookiecutter version of this repo at https://github.com/JackStouffer/cookiecutter-Flask-Foundation. Documentation is locat

Jack Stouffer 1.3k Dec 11, 2022
A Flask app template with integrated SQLAlchemy, authentication, and Bootstrap frontend

Flask-Bootstrap Flask-Bootstrap is an Flask app template for users to clone and customize as desired, as opposed to a Flask extension that you can ins

Eric S. Bullington 204 Dec 26, 2022
Sample Dockerized flask app deployed on Kubernetes on Azure using AKS

Sample Dockerized flask app deployed on Kubernetes on Azure using AKS

Ahmed khémiri 22 Sep 08, 2021
Criando um Bot com PYAUTOGUI e utilizando o Flask para Interface para Usuário

Criando um Bot com PYAUTOGUI e utilizando o Flask para Interface para Usuário O pyautogui foi escolhido pela possibilidade de fazer a identificação do

Rodrigo Vital 2 Oct 20, 2021
Flask 文档中文翻译

Flask 中文文档 这里是 Flask 文档中文翻译项目,欢迎参与! 在开始翻译之前,请务必阅读下面的 Contributing Guide 了解贡献流程,然后阅读这个 Issue 了解翻译要求,在这个 Discussion 投票选出你认为合适的翻译词汇,在这个 Discussion 投票选出你喜

Grey Li 93 Nov 28, 2022
Flask app for deploying DigitalOcean droplet using Pulumi.

Droplet Deployer Simple Flask app which deploys a droplet onto Digital ocean. Behind the scenes there's Pulumi being used. Background I have been Terr

Ahmed Sajid 1 Oct 30, 2021
Adds GraphQL support to your Flask application.

Flask-GraphQL Adds GraphQL support to your Flask application. Usage Just use the GraphQLView view from flask_graphql from flask import Flask from flas

GraphQL Python 1.3k Jan 03, 2023
Learn REST API with Flask, Mysql and Docker

Learn REST API with Flask, Mysql and Docker A project for you to learn to work a flask REST api with docker and the mysql database manager! Table of C

Aldo Matus 0 Jul 31, 2021
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 YouTube webscraper made with flask.

YouTube Webscraper This website is for you to check all the stats on your favorite Youtube video! Technologies Python Flask HTML CSS Pafy Contributing

Proconsulates 3 Nov 25, 2021
A Flask application for Subdomain Enumeration

subdomainer-flask A Flask application for Subdomain Enumeration steps to be done git clone https://github.com/gokulapap/subdomainer-flask pip3 install

GOKUL A.P 7 Sep 22, 2022
A flask template with Bootstrap 4, asset bundling+minification with webpack, starter templates, and registration/authentication. For use with cookiecutter.

cookiecutter-flask A Flask template for cookiecutter. (Supports Python ≥ 3.6) See this repo for an example project generated from the most recent vers

4.3k Dec 29, 2022
A simple barcode and QR code generator built in Python with Flask.

✨ Komi - Barcode & QR Generator ✨ A simple barcode and QR code generator built in Python with Flask. 📑 Table of Contents Usage Installation Contribut

Bonnie Fave 2 Nov 04, 2021
REST API with mongoDB and Flask.

Flask REST API with mongoDB py 3.10 First, to install all dependencies: python -m pip install -r requirements.txt Second, into the ./src/ folder, cop

Luis Quiñones Requelme 3 Mar 05, 2022
A multi-container docker application. Implemented and dockerized a web-based service leveraging Flask

Flask-based-web-service-with-Docker-compose A multi-container docker application. Implemented and dockerized a web-based service leveraging Flask. Des

Jayshree Rathi 1 Jan 15, 2022
YAML-formatted plain-text file based models for Flask backed by Flask-SQLAlchemy

Flask-FileAlchemy Flask-FileAlchemy is a Flask extension that lets you use Markdown or YAML formatted plain-text files as the main data store for your

Siddhant Goel 20 Dec 14, 2022