1

我正在尝试使用 Endless Pagination 实现 Twitter 样式的分页。问题是当我单击显示更多时,会显示“正在加载”,但更新的条目不会显示在浏览器中。我检查了ajax响应,它是正确的。当我将js放入另一个文件并调试时,我发现调试时更新了DOM,但我的浏览器没有显示更新的内容。有人可以帮助我吗?谢谢。

<div class="feeds endless_page_template">
      {% include page_template %}   
</div>
{% block js %}
    {{ block.super }}
     <script src="http://code.jquery.com/jquery-latest.js"></script>
     <script src="{{ STATIC_URL }}endless_pagination/js/endless-pagination.js"></script>
     <script>$.endlessPaginate();</script>
{% endblock %}

下面是我的 page_template

{% load endless %}
{% load custom_filters %}

{% lazy_paginate notifications %}

{% for notification in notifications %}
     <code to display notification>
{% endfor %}

{% show_more "show more"%}

这是我的视图类:

class HomeView(generic.ListView):
    page_template_name = 'archive/home.html'
    page_template = 'archive/notification.html'

@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
    return super(HomeView, self).dispatch(*args, **kwargs)

def get(self, request, template="archive/home.html", *args, **kwargs):
    try:
        #notification_list = retrieve_feed(request= request)
        notification_list = retrieve_checkups(request=request)
        <code to get notifications>

    context = {'notifications': notification_list, 'is_doctor': is_doctor, 'docpat': docpat,
               'totalp': totalp, 'newp': newp, 'totalc': totalc, 'newc': newc,
               'profile_picture': profile_picture, 'page_template': self.page_template}

    return render(request, template, context, context_instance=Util.custom_context(request))
4

1 回答 1

0

看来您缺少该if request.is_ajax(): template = page_template条款。

这会将模板从archive/home.html发出archive/notification.htmlajax 请求的时间更改为。因此,它将新模板包含在每个请求的较大模板中。

参考http://django-endless-pagination.readthedocs.io/en/latest/twitter_pagination.html#split-the-template

于 2016-05-09T13:12:27.913 回答