model:
class New(model.Model):
title = models.CharField(max_length=32)
Timenal: python manage.py shell
>>from .model import New
>>for i in range(100):
new = New.object.create(title="学习的第{}天".format(i))
new.save()
view.py
def get_news(request):
# page 当前页面 默认值为第一页
page = int(request.GET.data("page", 1))
# per_page 页面显示的数据量 默认值为8条
per_page = int(request.GET.data("per_page", 8))
# 获取所有的数据
new_list = New.objects.all()
# 将所有数据放到分页器中
paginator = Paginator(new_list, per_page)
page_object = paginator.page("page")