
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
django-keyset-pagination-plus
Advanced tools
Django pagination uses the LIMIT/OFFSET method. This is fine for smaller offsets, but once you start getting beyond a few pages, it can perform really badly. This is because the database needs to fetch all of the previous rows, even though it discards them.
Using Keyset Pagination allows for better performing "next page" fetches, at the cost of not being able to randomly fetch a page. That is, if you know the last element from page N-1, then you may fetch page N, but otherwise you really can't.
Keyset Pagination, sometimes called the Seek Method, has been documented by Markus Winand and Joe Nelson. If you are not familiar with the concept, I strongly suggest you read the articles above.
In order to use the paginator within this package, you will probably also need to use the provided View mixin: this changes the way a queryset is paginated to enable non-integer "page numbers".
class List(PaginationMixin, ListView):
paginator_class = KeysetPaginator
paginate_by = 10
queryset = MyModel.objects.order_by('-timestamp', 'group')
You won't be able to iterate through page numbers in a template in the same way: you are limited to next and previous pages. Otherwise, you construct them in largely the same way:
<a href="{% url 'mymodel:list' %}?page={{ page_obj.previous_page_number }}">
Prev Page
</a>
<a href="{% url 'mymodel:list' %}?page={{ page_obj.next_page_number }}">
Next Page
</a>
Note that you do not get access to the length of the queryset, nor the number of pages, because these could be expensive queries. You really don't need to know that ;)
However, I like to use GET forms to enable pagination of filtered results:
<button form="target-form"
name="page"
value="{{ page_obj.previous_page_number }}"
type="submit">
← Prev Page
</button>
<button form="target-form"
name="page"
value="{{ page_obj.next_page_number }}"
type="submit">
Next Page →
<button>
See https://schinckel.net/2018/11/23/keyset-pagination-in-django/ for more details about how this package works.
FAQs
Keyset Pagination (seek method) for django.
We found that django-keyset-pagination-plus demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.