分页插件叫django-pure-pagination,github地址https://github.com/jamespacileo/django-pure-pagination
安装介绍在他项目下已经介绍的很充分了
就补充几个需要注意的地方
# views.py
from django.views.generic import ListView
from pure_pagination.mixins import PaginationMixin
from my_app.models import MyModel
class MyModelListView(PaginationMixin, ListView):
# Important, this tells the ListView class we are paginating
paginate_by = 10
# Replace it for your model or use the queryset attribute instead
object = MyModel
这是对于通用类视图的情况,这个地方object = MyModel的意思我不太明白,我觉得这是传到模板里面的变量,但是我们之前都不是这样写的啊,所以我这里去掉了object = MyModel,因为我已经有了要传到模板里面的变量。
对于pagination.html这个模板
{% load i18n %}
<div class="pagination">
{% if page_obj.has_previous %}
<a href="?{
{ page_obj.previous_page_number.query