Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Add option SHOW_FIRST_PAGE_WHEN_INVALID #24

@barsch

Description

@barsch

It would be very useful to have an option to default to the first page if hitting a wrong page object.

I suggest to basically replace https://github.com/pydanny/dj-pagination/blob/master/dj_pagination/templatetags/pagination_tags.py#L186-L196 with something like this:

    try:
        page_obj = paginator.page(request.page(page_suffix))
    except InvalidPage:
        if INVALID_PAGE_RAISES_404:
            raise Http404(
                "Invalid page requested.  If DEBUG were set to "
                + "False, an HTTP 404 page would have been shown instead."
            )
        if SHOW_FIRST_PAGE_WHEN_INVALID
            # fallback to first page
            page_obj = paginator.page(1)
        else:
            context[key] = []
            context["invalid_page"] = True
            return ""

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions