When using Django CBV ListView
with pagination:
class Proposals(ListView):
model = Proposal
ordering = "id"
paginate_by = 10
In the browser, if I provide a page that is out of range, I get an error:
I would like to have a different behaviour: to fallback to the last existing page if the provided page is out of range.
I dug into Django source code paginator.py file and was surprised to find some code that does exactly this:
So using paginator.get_page(page)
(and not paginator.page(page)
) would be the way to go. However, ListView
does not use it as you can see here:
What is the best way to deal with this?
Thanks.