importying listviewin django
from django.views.generic import ListView,TemplateView
from django.views.generic.base import View
from django.views.generic.detail import DetailView
importying listviewin django
from django.views.generic import ListView,TemplateView
from django.views.generic.base import View
from django.views.generic.detail import DetailView
listview django
#views.py
#GeeksModel is a example model
from django.views.generic.list import ListView
from .models import GeeksModel
class GeeksList(ListView):
paginate_by=3
# specify the model for list view
model = GeeksModel
#Now create a url path to map the view. In geeks/urls.py,
from django.urls import path
# importing views from views..py
from .views import GeeksList
urlpatterns = [
path('', GeeksList.as_view()),
]
#in your template you can manipulate pagination
{% for contact in page_obj %}
{# Each "contact" is a Contact model object. #}
{{ 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>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us