设为首页 加入收藏

TOP

django 分页出现 UnorderedObjectListWarning 错误
2018-10-19 16:52:20 】 浏览:30
Tags:django 出现 UnorderedObjectListWarning 错误

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'

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇python re库入门(正则表达式) 下一篇NO.5:自学python之路------标准..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目