3
我想在滾動上使用django-endless-pagination實現連續分頁。無盡的分頁加載滾動的整個頁面內容
該頁面的初始渲染正常工作。但是,一旦滾動,html頁面內容將被加載到endless_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
我/ 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>
我/ 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>
謝謝!
TBH,從你的代碼中我們可以看到關於分頁的任何內容。如果這確實是django和分頁問題,那麼首先應該包含您的視圖部分,該部分涉及分頁。在這篇文章中,我們沒有看到:1)分頁,2)在JavaScript中,你指的是哪個頁面或哪些對象應該包含在下一頁/批處理中。你在模板中也有show_more標籤,但它有什麼作用? –
@Odif Yltsaeb,謝謝你評論我的問題。我意識到我的錯誤,並通過澄清我正在使用django-endless-pagination應用程序更新了我的帖子。謝謝。 – pymarco
那麼,如果這是你可以給的所有信息,那麼我會說,問題是在你的查詢中,你返回的所有對象沒有分頁的對象列表.... –