每个模型都有一个管理器,Manager

python-django-分页处理

 

 

通过分页可以先加载一部分的数据内容,然后避免大量的查询带来的等待时间

python-django-分页处理

 

 python-django-分页处理

 

 python-django-分页处理

 

 

应用场景是,排行榜,前十条或者

python-django-分页处理

 

 

for i in range(100):
  ...:   ...:     list.append(User(username='duser{0}'.format(i),password='pp',nickname='nname'))
  ...:   
len(list)
Out[7]: 100
User.objects.bulk_create(list)
obj_list = User.objects.all()[50:10]
obj_list
Out[10]: <QuerySet []>
list_all = User.objects.all()
list_all[50:60]

python-django-分页处理

 

 

python-django-分页处理

这个objects是分页数据就是我们之前查询获得的结果集

python-django-分页处理

 

 python-django-分页处理

 

 python-django-分页处理

 

 

通过has_next实现,当没有下一页的时候将下一页的按钮禁用掉

python-django-分页处理

 

 

 

 

python-django-分页处理

 

 

 

python-django-分页处理

 

 python-django-分页处理

 

相关文章:

  • 2021-05-31
  • 2021-08-10
  • 2022-01-26
  • 2021-12-04
  • 2021-07-03
  • 2022-12-23
  • 2022-01-07
  • 2021-10-28
猜你喜欢
  • 2021-08-03
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2021-09-29
  • 2022-12-23
相关资源
相似解决方案