https://docs.djangoproject.com/en/dev/topics/pagination/?from=olddocs/
http://www.tummy.com/Community/Articles/django-pagination/
http://stackoverflow.com/questions/11433810/djangoquerying-database
Django provides this functionality already with a
Paginator
object. In your URL you'll need a page
parameter that says on which page you are and in your view you need to construct a Paginator
object. You need to specify the number of objects on a page (in your case 10) and the Paginator
will do the rest.
For example, the following code will print all instances that are displayed on page 3:
from django.core.paginator import Paginator
objects = messages.objects.all()
p = Paginator(objects, 10)
page3 = p.page(3)
print page3.object_list
The documentation gives examples on how to implement your views and how to pass the list of objects to your template.
No comments:
Post a Comment