我正在尝试使用django-endless-pagination在滚动上实现连续分页。
页面的初始渲染工作正常。然而,一旦滚动,整个html 页面内容将被加载到 never_page_template div 中,而不是 page_template 中所需的部分 html 内容。结果有点像看着一面镜子,镜子后面反射着另一面镜子。我相信返回的查询集是正确的,因为在不尝试使用“paginateOnScroll”时分页结果是正确的。
我的观点的相关部分如下。我正在使用 CreateView,因为我的评论表单与分页评论位于同一页面上。
class MyIndex(CreateView):
form_class = CommentForm
template_name = 'my/index.html'
page_template = 'my/comments.html'
def get_context_data(self, **kwargs):
context = super(MyIndex, self).get_context_data(**kwargs)
context.update({
'comments': Comment.objects.order_by('-id').filter(parent=None),
'page_template': self.page_template,
})
return context
my/index.html 模板(主模板)的相关部分
<script src="{% static 'endless_pagination/js/endless-pagination.js' %}"></script>
<script type="text/javascript">
$.endlessPaginate({
paginateOnScroll: true
});
</script>
<div class="endless_page_template">
{% include page_template %}
</div>
my/comments.html (page_template) 的相关部分
{% load endless %}
{% paginate comments %}
{% for comment in comments %}
<span class="lead">{{ comment.name }}</span>
{{ comment.message}}
{% if not forloop.last %}
<hr />
{% endif %}
{% endfor %}
<br />
<div class="row-fluid">
<div class="span8 offset2 pagination-centered">
{% show_more %}
</div>
</div>
谢谢!