django list_view code example
Example: listview django
from django.views.generic.list import ListView
from .models import GeeksModel
class GeeksList(ListView):
paginate_by=3
model = GeeksModel
from django.urls import path
from .views import GeeksList
urlpatterns = [
path('', GeeksList.as_view()),
]
{% for contact in page_obj %}
{
{{ contact.full_name|upper }}<br>
...
{% endfor %}
<div class="pagination">
<span class="step-links">
{% if page_obj.has_previous %}
<a href="?page=1">« first</a>
<a href="?page={{ page_obj.previous_page_number }}">previous</a>
{% endif %}
<span class="current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}">next</a>
<a href="?page={{ page_obj.paginator.num_pages }}">last »</a>
{% endif %}
</span>
</div>