我已经将一些已排序的查询集传递给模板。每页显示多个分页。问题出在第一系列分页项目之后,后续分类失败了。这是我的代码:
views.py
def entry_index(request, parent_cat, child_cat, template='entry_index.html',
page_template='entry_index_page.html'):
context = { 'items_by_percentage_saved':
Item.objects.filter(category=category).order_by('-percentage_saved'), }
if request.is_ajax():
template = page_template
return render_to_response(template, context,
context_instance=RequestContext(request))
by_percentage_saved.html
{% load endless %}
{% paginate items_by_percentage_saved %}
{% for item in items_by_percentage_saved %}
<div class="large-4 small-6 columns">
<a class="th" href=""><img style="height: 12em;" src={{ item.image_url }}></a>
<div class="panel">
<h5>{{ item.title|truncatechars:50 }}</h5>
...
</div>
</div>
{% endfor %}
{% show_more %}
更新
我已经做了一些调试,items_by_percentage_saved
查询集肯定是在entry_index()
中排序的。我在by_percentage_saved.html
中放了一些断点,看看我是否能弄清楚最新情况,但奇怪的是,点击“更多”以获取下一个分页数据后,再次调用entry_index()
但是断点从不会触发在by_percentage_saved.html
中第二次,即使生成了新的分页数据。谈论混乱
答案 0 :(得分:0)
好的已经通过再次浏览文档并使用页面装饰器来解决它。文档有点让它听起来像是可选的,但我猜他们是同一页面上多重分页的要求。
from endless_pagination.decorators import page_template
@page_template('entry_index_page.html')
@page_template('by_percentage_saved.html', key='by_percentage_saved')
def entry_index(request, parent_cat, child_cat, template='entry_index.html',
extra_context=None):