Django 分页对象与 Postgresql QuerySets 存在问题
我有一些 django 代码在 SQLite 数据库或 MySQL 数据库上运行良好,但它在 Postgres 上遇到问题,这让我抓狂,因为以前没有人遇到过这个问题。我认为这也可能与寻呼机评估查询集的方式有关。
在一个视图中,我有:
def index(request, page=1):
latest_posts = Post.objects.all().order_by('-pub_date')
paginator = Paginator(latest_posts, 5)
try:
posts = paginator.page(page)
except (EmptyPage, InvalidPage):
posts = paginator.page(paginator.num_pages)
return render_to_response('blog/index.html', {'posts' : posts})
在模板内部:
{% for post in posts.object_list %}
{# some rendering jazz #}
{% endfor %}
这与 SQLite 配合得很好,但 Postgres 给了我:
Caught TypeError while rendering: 'NoneType' object is not callable
为了使事情进一步复杂化,当我将 Queryset 调用切换为:
latest_posts = Post.objects.all()
一切都很好。我尝试重新阅读文档,但一无所获,尽管我承认此时我有点沮丧。我缺少什么?
提前致谢。
I have some django code that runs fine on a SQLite database or on a MySQL database, but it runs into problems with Postgres, and it's making me crazy that no one has has this issue before. I think it may also be related to the way querysets are evaluated by the pager.
In a view I have:
def index(request, page=1):
latest_posts = Post.objects.all().order_by('-pub_date')
paginator = Paginator(latest_posts, 5)
try:
posts = paginator.page(page)
except (EmptyPage, InvalidPage):
posts = paginator.page(paginator.num_pages)
return render_to_response('blog/index.html', {'posts' : posts})
And inside the template:
{% for post in posts.object_list %}
{# some rendering jazz #}
{% endfor %}
This works fine with SQLite, but Postgres gives me:
Caught TypeError while rendering: 'NoneType' object is not callable
To further complicate things, when I switch the Queryset call to:
latest_posts = Post.objects.all()
Everything works great. I've tried re-reading the documentation, but found nothing, although I admit I'm a bit clouded by frustration at this point. What am I missing?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我来说是一个可怕的错误,不能归咎于 Postgresql - 这个问题是由于我的自定义模板标签之一处理 postgresql 数据库中的某些帖子的方式而出现的,而这些帖子在 SQLite 数据库中不存在。我仍在弄清楚这个问题,但这个问题是无效的。
This was a terrible mistake on my part, no blame goes to Postgresql - the issue was popping up with the way one of my custom template tags was handling certain posts in the postgresql database that weren't present in the SQLite one. I'm still figuring out the issue, but this question is invalid.