Flask – Paginate

pip install -U flask-paginate

app.py :

from flask_paginate import Pagination, get_page_args


def home():
        page, per_page, offset = get_page_args(page_parameter='page',
                                               per_page_parameter='per_page')

        total = len(get_data())

        # total = jumlah data

        pagination_users = get_data_pag(offset=offset, limit=per_page)

        # get_data_pag = select data dgn limit & offset

        pagination = Pagination(page=page, per_page=per_page, total=total,
                                css_framework='bootstrap4', 
                                show_single_page=True)

        return render_template('home.html',
                               users=pagination_users,
                               page=page,
                               per_page=per_page,
                               pagination=pagination,
                               )

home.html :

{% for x in users %}

   {{ x['title']|safe }}

{% endfor %}


{{ pagination.links }}

Leave a Reply

Your email address will not be published. Required fields are marked *