Django Endless Pagination twitter风格分页不起作用(更改不反映在HTML上)

时间:2015-06-26 23:52:28

标签: javascript jquery django pagination django-endless-pagination

我正在尝试使用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))

1 个答案:

答案 0 :(得分:0)

您似乎错过了if request.is_ajax(): template = page_template子句。

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

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