开发者

django-pagination not working

开发者 https://www.devze.com 2023-02-05 18:19 出处:网络
My category.html page is like this right now and the pagination is not working. It doesn\'t even show any error.

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开发者_如何学C 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.


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:

category_entries = category.entries.all()

remember to add category_entries to your template context and change category.entries.all to category_entries in your template.

0

精彩评论

暂无评论...
验证码 换一张
取 消