django 分页不工作
我的category.html 页面现在是这样的,分页不起作用。它甚至没有显示任何错误。
{% autopaginate category.entries.all 5 %} #line 17
{% for entry in category.entries.all %}
<li><a href="{{ entry.get_absolute_url }}">{{ entry.name }}</a></li>
另一方面,当我将catehory.html 中的第17 行更改为以下内容时:
{% autopaginate category.entries.all 5 %} #line 17
它给了我巨大的模板语法错误。 http://pastebin.com/E4zfCt0v
我也在另一个页面上使用 django-pagination 进行分页,并且它正在工作那里很好。我想我可能没有正确检索条目,但如果是这种情况,那么 {% for entry in Category.entries.all %} 也不应该工作,这工作正常。我正在获取所有条目,但只是没有在此特定页面上分页。
My category.html page is like this right now and the pagination is not working. It doesn't even show any error.
{% autopaginate category.entries.all 5 %} #line 17
{% for entry in category.entries.all %}
<li><a href="{{ entry.get_absolute_url }}">{{ entry.name }}</a></li>
When on the other hand I change the line 17 in the catehory.html to the following:
{% autopaginate category.entries.all 5 %} #line 17
it gives me huge template syntax error. http://pastebin.com/E4zfCt0v
I am using pagination using django-pagination on another page too and it is working fine there. I think I am probably not retrieving the entries correctly but if that was the case then {% for entry in category.entries.all %} shouldn't have worked either, which is working fine. I am getting all the entries but it is just not getting paginated on this particular page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来自动分页标记无法将变量 category.entries.all 解析为有效对象(在本例中为查询集)。应该有效的快速修复方法是从名为category_entries(或给它其他名称)的视图变量传递,该变量将保存已解析的查询集:
记住将category_entries添加到模板上下文中并将category.entries.all更改为模板中的category_entries。
Looks like the autopaginate tag cannot resolve variable category.entries.all into a valid object (queryset in this case). Quick fix that should work is to pass from your view variable named category_entries (or give it some other name) which will hold already resolved queryset:
remember to add category_entries to your template context and change category.entries.all to category_entries in your template.