由于这是一个广泛的问题,我现在想结合几种分页解决方案。
1.使用通用的ListView https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#listview:
from django.views.generic import ListView
class EntryList(ListView):
model = Entry
template_name = 'blog/entry_list.html'
context_object_name = 'entry_list'
paginate_by = 10
仅使用会更快urls.py
:
url(r'^entries/$', ListView.as_view(model=Entry, paginate_by=10))
所以基本上在这个解决方案中你不需要 django-endless-pagination 。您可以在此处查看模板示例:如何使用基于 Django 类的通用 ListView 的分页? https://stackoverflow.com/questions/5907575/how-do-i-use-pagination-with-django-class-based-generic-listviews
2.使用django-endless-paginationAjax列表视图 http://django-endless-pagination.readthedocs.org/en/latest/generic_views.html:
from endless_pagination.views import AjaxListView
class EntryList(AjaxListView):
model = Entry
context_object_name = 'entry_list'
page_template = 'entry.html'
或者更快(再次)urls.py
only:
from endless_pagination.views import AjaxListView
url(r'^entries/$', AjaxListView.as_view(model=Entry))
参考:http://django-endless-pagination.readthedocs.org/en/latest/generic_views.html http://django-endless-pagination.readthedocs.org/en/latest/generic_views.html
如果有人知道不同的解决方案,请评论。