Django paginator and raw SQL

旧时模样 提交于 2019-12-11 10:57:09

问题


I'm having trouble using djangoś paginator function. In this question i can't find the solution: Django: Paginator + raw SQL query

With Table.object.all() i have no trouble, but with raw sql i receive the error object of type 'RawQuerySet' has no len()

I tried also

num = len(list(ads)) paginator = Paginator(num, 2)

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.


回答1:


Found the solution here: http://groups.google.com/group/django-users/browse_thread/thread/42cf7b5a88f31b9c

that means:

paginator = Paginator((list(ads)), 10)


来源:https://stackoverflow.com/questions/10214030/django-paginator-and-raw-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!