Skip to main content

codecov version downloads license

This package is used to create standard or cursor navigation for django.

It has builtin templates, so you can use this library with minimal effort. Library can be used with jinja2 templates. If you are using django_jinja package, additional template tags are automatically registered to jinja2 engine.

If you are using cursor pagination, the queryset must be ordered with combination of data fields, which are unique across query.

Cursor pagination supports checking for next / previous page presence without any additional queries. There is used only single query to select records, no additional queries to count checking or next / previous checking.

Install

pip install django-universal-paginator

To INSTALLED_APPS add django_universal_paginator.

INSTALLED_APPS = (
        # ...
        'django_universal_paginator',
)

Settings

Classical paginator support following settings:

PAGINATOR_ON_EACH_SIDE

Count of links around current page, default: 3

PAGINATOR_ON_ENDS

Link count on start / end of list, default: 1

PAGINATOR_TEMPLATE_NAME

Default template name for paginator, default: 'paginator/paginator.html'

Usage

Template

To use this library first add {% pagination %} to django template or {{ pagination() }} to jinja2 template.

<!-- object_list.html -->
{% load paginator_tags %}

<ul>
        {% for object in object_list %}
                <li>{{ object }}</li>
        {% endfor %}
</ul>

<div class="pagination">{% pagination %}</div>

To modify style look to paginator.html.

URLs

This package can be used without URL modification, but if you want clean URL patterns without GET parameters, like /object-list/3/, you can use following code (example contains both methods - standard and cursor).

# urls.py

from django.urls import path, register_converter
from django_universal_paginator.converter import PageConverter, CursorPageConverter

register_converter(PageConverter, 'page')
register_converter(CursorPageConverter, 'cursor_page')

# standard
url(r'^object-list/<page:page>', ObjectList.as_view(), name='object_list'),
# or cursor
url(r'^cursor/<cursor_page:page>', ObjectList.as_view(), name='cursor_list'),

Classical navigation

To use classical navigation, just add paginate_by attribute to class based list view.

# views.py

class ObjectList(ListView):
        paginate_by = 10
        # model = ...

If you are using function based views, you can use django_universal_paginator.utils.paginate_queryset.

# views.py
from django_universal_paginator.utils import paginate_queryset

def list_view(request):
        queryset = Book.objects.order_by('pk')
        paginate_by = 10
        page = 1
        paginator, page, queryset, is_paginated = self.paginate_queryset(queryset, page,
        paginate_by)

        context = {
                "paginator": paginator,
                "page_obj": page,
                "is_paginated": is_paginated,
                "object_list": queryset,
        }

        reutrn render_to_string("list.html", context)

Cursor pagination

To use cursor pagination, queryset must be correctly ordered (order key must be combination of keys which are unique across queryset).

# views.py
from django.views.generic import ListView
from django_universal_paginator.cursor import CursorPaginateMixin

class List(CursorPaginateMixin, ListView):
        paginate_by = 10
        queryset = Book.objects.order_by('pk')

Metadata

Release files for django-universal-paginator 1.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-universal-paginator 1.4.0
File Size Uploaded Provenance
django_universal_paginator-1.4.0.tar.gz 31.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-universal-paginator 1.4.0
File Interpreter ABI Platform
django_universal_paginator-1.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 44.6 kB

Release files / django_universal_paginator-1.4.0.tar.gz

Download URL django_universal_paginator-1.4.0.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7f29974c2ff104bd7b86dfb12e6222893834249d0878fe9febf5a6ad01cada49
BLAKE2b-256 checksum
How to use checksums
40781ab3790bcfa4bc7c8de1983e699f0deae156cd4e48e6ddeb81c6603cfa46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.12

Release files / django_universal_paginator-1.4.0-py3-none-any.whl

Download URL django_universal_paginator-1.4.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1c37f518a16a903c7e23c7c29b685864961bb9a951f9cf7d29219da14232c3c
BLAKE2b-256 checksum
How to use checksums
6503f37cceb710df8919587c00fa5a2ebf1e6851a001a057be16d5d224ca0aea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.12

Security for django-universal-paginator 1.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page