1#views.py
2#GeeksModel is a example model
3from django.views.generic.list import ListView
4from .models import GeeksModel
5
6class GeeksList(ListView):
7 paginate_by=3
8 # specify the model for list view
9 model = GeeksModel
10
11#Now create a url path to map the view. In geeks/urls.py,
12
13from django.urls import path
14
15# importing views from views..py
16from .views import GeeksList
17urlpatterns = [
18 path('', GeeksList.as_view()),
19]
20
21#in your template you can manipulate pagination
22{% for contact in page_obj %}
23 {# Each "contact" is a Contact model object. #}
24 {{ contact.full_name|upper }}<br>
25 ...
26{% endfor %}
27
28<div class="pagination">
29 <span class="step-links">
30 {% if page_obj.has_previous %}
31 <a href="?page=1">« first</a>
32 <a href="?page={{ page_obj.previous_page_number }}">previous</a>
33 {% endif %}
34
35 <span class="current">
36 Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
37 </span>
38
39 {% if page_obj.has_next %}
40 <a href="?page={{ page_obj.next_page_number }}">next</a>
41 <a href="?page={{ page_obj.paginator.num_pages }}">last »</a>
42 {% endif %}
43 </span>
44</div>