django 分页出现此错误:

UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list: <class 'monitor.models.HostBind'> QuerySet.
  allow_empty_first_page=allow_empty_first_page, **kwargs)

原因为:

view代码中没有进行排序指定,

class MonitorListView(PaginateListView):
    model = Monitors   
    template_name = 'monitors_list.html'
    context_object_name = 'monitor_list'
    page_kwarg = 'page'
    ordering = 'name'  ##加入ordering排序

或者使用

class MonitorListView(PaginateListView):
    queryset = Monitors.objects.all().order_by('name')   
    template_name = 'monitors_list.html'
    context_object_name = 'monitor_list'
    page_kwarg = 'page'

 

相关文章:

  • 2022-02-04
  • 2021-04-16
  • 2022-12-23
  • 2021-06-17
  • 2021-10-10
  • 2021-09-17
  • 2021-06-29
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-17
  • 2022-02-24
  • 2022-12-23
  • 2021-08-19
  • 2021-04-24
  • 2021-10-23
相关资源
相似解决方案