Skip to main content

BasePaginator

This class provides a base implementation for splitting a list of objects into manageable pages. It handles page validation, supports elided page ranges for compact navigation, and allows for a configurable number of orphan items to be merged into the final page. The class also includes built-in warnings for unordered data sources to ensure consistent pagination results.

Attributes

AttributeTypeDescription
ELLIPSISstring = …String used to replace omitted page numbers in elided page range generated by paginators, e.g. [1, 2, '…', 5, 6, 7, '…', 9, 10].
default_error_messagesdictA dictionary containing the default translated error messages for invalid page numbers, minimum page violations, and empty results.

Constructor

Signature

def BasePaginator(
object_list: list,
per_page: int,
orphans: int = 0,
allow_empty_first_page: boolean = True,
error_messages: dict = null
) - > null

Parameters

NameTypeDescription
object_listlistA list, tuple, QuerySet, or other sliceable object with a count() or len() method.
per_pageintThe maximum number of items to include on a page, excluding orphans.
orphansint = 0The minimum number of items allowed on the last page.
allow_empty_first_pageboolean = TrueWhether the first page is allowed to be empty.
error_messagesdict = nullA dictionary containing custom error messages to override the defaults.