{"id":7239,"library":"flask-paginate","title":"Flask-Paginate","description":"Flask-Paginate provides simple pagination support for Flask applications, making it easy to display large datasets across multiple pages. It handles page number generation, URL building, and integrates with various CSS frameworks like Bootstrap. The current version is 2024.4.12, following a date-based release cadence with frequent updates for bug fixes and compatibility.","status":"active","version":"2024.4.12","language":"en","source_language":"en","source_url":"https://github.com/lixxu/flask-paginate","tags":["flask","pagination","web","frontend"],"install":[{"cmd":"pip install flask-paginate","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core web framework integration.","package":"Flask","optional":false},{"reason":"For HTML rendering, explicitly required for Flask 3+ compatibility.","package":"MarkupSafe","optional":false}],"imports":[{"note":"The primary class for creating pagination objects.","symbol":"Pagination","correct":"from flask_paginate import Pagination"},{"note":"Utility to get the page argument from request parameters, supporting custom argument names.","symbol":"get_page_parameter","correct":"from flask_paginate import get_page_parameter"},{"note":"Utility to get the per_page argument from request parameters.","symbol":"get_per_page_parameter","correct":"from flask_paginate import get_per_page_parameter"}],"quickstart":{"code":"import os\nfrom flask import Flask, render_template, request\nfrom flask_paginate import Pagination, get_page_parameter\n\napp = Flask(__name__)\napp.secret_key = os.environ.get('FLASK_SECRET_KEY', 'a_secret_key_for_dev')\n\n# Sample data\nUSERS = [str(i) for i in range(1, 101)]\n\n@app.route('/')\ndef index():\n    page = request.args.get(get_page_parameter(), type=int, default=1)\n    per_page = 10\n    offset = (page - 1) * per_page\n    \n    users_for_page = USERS[offset:offset + per_page]\n    total = len(USERS)\n\n    pagination = Pagination(\n        page=page, per_page=per_page, total=total,\n        css_framework='bootstrap4',\n        record_name='users'\n    )\n\n    # In a real app, you would have an 'index.html' template\n    # For this example, we'll return a minimal string.\n    # In your template, you would use: {{ pagination.render_macro('pagination.html') }}\n    return f\"\"\"<!doctype html>\n<html lang='en'>\n<head>\n    <meta charset='utf-8'>\n    <meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>\n    <link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css' integrity='sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N' crossorigin='anonymous'>\n    <title>Flask-Paginate Example</title>\n</head>\n<body>\n    <div class='container'>\n        <h1>Users</h1>\n        <ul>\n            {''.join([f'<li>User {user}</li>' for user in users_for_page])}\n        </ul>\n        <div class='text-center'>\n            {pagination.render_macro('pagination.html')}\n        </div>\n    </div>\n</body>\n</html>\"\"\"\n\nif __name__ == '__main__':\n    app.run(debug=True)\n","lang":"python","description":"This quickstart sets up a basic Flask application with pagination for a list of 100 users. It demonstrates how to retrieve the current page number, slice the data accordingly, and initialize the `Pagination` object. It uses Bootstrap 4 for styling and renders the pagination controls directly using `pagination.render_macro('pagination.html')`."},"warnings":[{"fix":"Update your `Pagination` constructor calls to use `include_first_page_number` instead of `show_first_page_number`.","message":"The `show_first_page_number` parameter in the `Pagination` constructor was renamed to `include_first_page_number`.","severity":"breaking","affected_versions":"< 2024.3.28"},{"fix":"Upgrade `flask-paginate` to version `2023.10.8` or newer to ensure compatibility with Flask 3.0 and above. This version internally updates the `Markup` import path.","message":"Older versions of `flask-paginate` (prior to 2023.10.8) are incompatible with Flask 3.0+ due to changes in how `Markup` is imported by Flask.","severity":"breaking","affected_versions":"flask-paginate < 2023.10.8 (when used with Flask >= 3.0)"},{"fix":"If your templates are still based on Bootstrap 3 or you notice styling issues, explicitly set `css_framework='bootstrap3'` in the `Pagination` constructor, or update your templates to use Bootstrap 4/5 classes. `flask-paginate` also supports 'bootstrap5' directly.","message":"The default CSS framework changed from Bootstrap 3 to Bootstrap 4.","severity":"gotcha","affected_versions":"All versions from 2021.10.26 onwards"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Replace `show_first_page_number` with `include_first_page_number` in your `Pagination` constructor call.","cause":"You are using an outdated argument name for including the first page number in the pagination links.","error":"TypeError: Pagination.__init__() got an unexpected keyword argument 'show_first_page_number'"},{"fix":"Upgrade `flask-paginate` to version `2023.10.8` or a newer version. `pip install --upgrade flask-paginate`.","cause":"This error occurs when running an older version of `flask-paginate` (prior to 2023.10.8) with Flask 3.0 or newer. Flask 3 moved the `Markup` class from `flask` to `markupsafe`.","error":"ImportError: cannot import name 'Markup' from 'flask'"},{"fix":"Explicitly set `css_framework='bootstrap3'` in the `Pagination` constructor if you intend to use Bootstrap 3, or update your HTML templates to comply with Bootstrap 4 or 5 styling, then set `css_framework='bootstrap4'` or `css_framework='bootstrap5'` respectively.","cause":"The default CSS framework for `flask-paginate` changed from Bootstrap 3 to Bootstrap 4 in version 2021.10.26. Your template HTML might be expecting Bootstrap 3.","error":"Pagination links or styling appear broken after upgrading `flask-paginate` or `Flask`."}]}