django分页和RawQuerySet [英] django pagination and RawQuerySet
本文介绍了django分页和RawQuerySet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我把它转换为一个列表,它会在我的脸上抛出一个错误... TypeError:预期的字符串或Unicode对象,找到NoneType。有没有办法解决这个问题?
解决方案
我设法使用以下方式实现:
paginator = Paginator(files,12)
/ pre>
paginator._count = len(list(files))
django.core.paginator.py中的代码:
- 检查_count是否设置
- 如果没有,则尝试运行不存在的.count()
- 如果没有尝试plain len
len on raw_queryset不起作用,但将实际的paginator对象转换为列表可以在Django 1.3中为我找到。
is there a way to paginate a rawqueryset using django's inbuilt pagination? when i cast it to a list , it throws an error in my face ...TypeError: expected string or Unicode object, NoneType found. Is there a way around this?
解决方案
I managed to achieve it using the following:
paginator = Paginator(files, 12)
paginator._count = len(list(files))
The code in django.core.paginator.py:
- checks for whether _count is set
- if not then tries to run .count() which doesn't exist
- if not then tries plain len
len on a raw_queryset doesn't work but converting the actual paginator object to a list works find for me in Django 1.3
这篇关于django分页和RawQuerySet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文