当前位置: 移动技术网 > IT编程>脚本编程>Python > django 分页出现 UnorderedObjectListWarning 错误

django 分页出现 UnorderedObjectListWarning 错误

2018年06月28日  | 移动技术网IT编程  | 我要评论

联想电脑如何一键还原,血色浪漫小说,机顶盒影音分配器

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'

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网