我可以自定义ListView的分页过程吗?例如,如果我们发送了不可数的字符串,我想在Exception
后面加上一些ValueError
。还是只需要覆盖paginate_queryset
方法?
答案 0 :(得分:0)
您尝试过这样的事情吗?
page = request.GET.get('page')
paginator = Paginator(blogs, 10)
try:
blogs = paginator.page(page)
except PageNotAnInteger:
blogs = paginator.page(1)
except EmptyPage:
blogs = paginator.page(paginator.num_pages)
来源:https://www.programcreek.com/python/example/50824/django.core.paginator.EmptyPage