Django分页器和原始SQL [英] Django paginator and raw SQL
问题描述
我在使用djangoś分页器功能时遇到问题.在这个问题中,我找不到解决方案: Django:Paginator +原始SQL查询
I'm having trouble using djangoś paginator function. In this question i can't find the solution: Django: Paginator + raw SQL query
使用Table.object.all()
我没有问题,但是使用原始sql我收到错误object of type 'RawQuerySet' has no len()
With Table.object.all()
i have no trouble, but with raw sql i receive the error object of type 'RawQuerySet' has no len()
我也尝试过
num = len(list(ads)) paginator = Paginator(num,2)
num = len(list(ads)) paginator = Paginator(num, 2)
,我收到object of type 'int' has no len()
.我尝试打印num,它包含正确的数字,所以我不明白为什么分页器不喜欢它.希望有人能帮忙.
and i receive object of type 'int' has no len()
. I tried to print num and it contains the correct number so i don't understand why paginator doesn't like it. Hope someone can help.
推荐答案
在此处找到了解决方案: http://groups.google.com/group/django-users/browse_thread/thread/42cf7b5a88f31b9c
Found the solution here: http://groups.google.com/group/django-users/browse_thread/thread/42cf7b5a88f31b9c
这意味着:
paginator = Paginator((list(ads)), 10)
这篇关于Django分页器和原始SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!