Skip to main content

Page

This class represents a single page of results within a larger paginated collection. It acts as a sequence, providing access to a subset of objects while offering methods to navigate between pages and determine the page's position relative to the total dataset. Key features include the ability to check for neighboring pages and calculate the 1-based start and end indices of the current result set.

Attributes

AttributeTypeDescription
object_listsequenceA list or sequence of objects contained within this specific page.
numberintThe 1-based page number representing the current position within the paginator.
paginator[Paginator](paginator.md?sid=django_core_paginator_paginator)The Paginator instance that created this page, used to access pagination metadata and validation.

Constructor

Signature

def Page(
object_list: list,
number: int,
paginator: [Paginator](paginator.md?sid=django_core_paginator_paginator)
)

Parameters

NameTypeDescription
object_listlistA list, QuerySet, or other sliceable collection of objects for the page.
numberintThe 1-based page number for this page instance.
paginator[Paginator](paginator.md?sid=django_core_paginator_paginator)The Paginator object that created this page.

Methods


has_next()

@classmethod
def has_next() - > boolean

Checks if there is a subsequent page available after the current one.

Returns

TypeDescription
booleanTrue if the current page number is less than the total number of pages, otherwise False.

has_previous()

@classmethod
def has_previous() - > boolean

Checks if there is a preceding page available before the current one.

Returns

TypeDescription
booleanTrue if the current page number is greater than one, otherwise False.

has_other_pages()

@classmethod
def has_other_pages() - > boolean

Determines if there are any other pages available, either before or after the current page.

Returns

TypeDescription
booleanTrue if either a previous or next page exists, otherwise False.

next_page_number()

@classmethod
def next_page_number() - > integer

Calculates and validates the page number for the next page.

Returns

TypeDescription
integerThe validated integer representing the next page number.

previous_page_number()

@classmethod
def previous_page_number() - > integer

Calculates and validates the page number for the previous page.

Returns

TypeDescription
integerThe validated integer representing the previous page number.

start_index()

@classmethod
def start_index() - > integer

Return the 1-based index of the first object on this page, relative to total objects in the paginator.

Returns

TypeDescription
integerThe 1-based position of the first item on the page, or 0 if the paginator is empty.

end_index()

@classmethod
def end_index() - > integer

Return the 1-based index of the last object on this page, relative to total objects found (hits).

Returns

TypeDescription
integerThe 1-based position of the last item on the page, accounting for orphans on the final page.