Paginate is a Python module that helps divide large lists of items into pages for easier browsing. It's a standalone library, previously maintained as `webhelpers.paginate`, and aims to be framework-agnostic. The current version is 0.5.7, last updated in August 2024, indicating active maintenance for its core functionality.
pip install paginateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to paginate a simple list using the `Page` class. It shows how to initialize `Page` with a collection, current page, and items per page, and how to define a `url_maker` function. It then accesses the items for the current page and generates basic pagination links.
Migrate to the standalone `paginate` module. For SQLAlchemy integration, install and use `paginate_sqlalchemy`. Refactor code that relied on `presliced_list`.
Replace all instances of `page_nr` or `current_page` with `page` when initializing or accessing the `Page` object.
Implement a `url_maker` function and pass it to the `Page` constructor, or explicitly pass a `url` string with `$page` placeholder to `pager()`. Apply CSS classes via `link_attr`, `curpage_attr`, `dotdot_attr` parameters to `pager()` or use `link_map()` for custom rendering in templates.
Account for 1-based indexing when calculating offsets or mapping page numbers to 0-indexed data structures.
For performance-critical applications or large datasets, pre-calculate the total item count and pass it as the `item_count` parameter to the `Page` constructor.
Ensure the 'paginate' library is installed using pip: `pip install paginate`
Correctly instantiate a Page object: `from paginate import Page; my_list = [1, 2, 3, ...]; current_page = 1; items_per_page = 10; paginator = Page(my_list, page=current_page, items_per_page=items_per_page)`
Iterate over the 'items' attribute of the Page object: `from paginate import Page; my_list = [1, 2, 3, ...]; paginator = Page(my_list, page=1, items_per_page=10); for item in paginator.items: print(item)`
Install the 'paginate' library (`pip install paginate`) and update your import statements from `from webhelpers.paginate import Page` to `from paginate import Page`. You may also need to adjust other API calls as the standalone 'paginate' library has a slightly different interface.
No dependency data recorded yet.