无尽的分页加载滚动的整个页面内容 [英] Endless pagination loads entire page contents on scroll

查看:186
本文介绍了无尽的分页加载滚动的整个页面内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 django-endless-pagination

页面的初始渲染工作正常。一旦滚动,然而,整个 html页面内容将加载到endless_page_template div中,而不是从page_template中的所需部分html内容。结果就像看着镜子里面反映了另一个镜子。我认为返回的查询器是正确的,因为在不尝试使用paginateOnScroll时,分页结果是正确的。

The initial rendering of the page works fine. Once scrolled, however, the entire html page contents are loaded into the endless_page_template div, rather than the desired partial html content from the page_template. The result is sort of like looking into a mirror that is reflecting another mirror behind it. I believe that the queryset returned is correct because the pagination results are correct when not attempting to use "paginateOnScroll".

我的观点的相关部分如下。我正在使用一个CreateView,因为我有与分页评论相同页面上的评论表单。

The relevant parts of my view are below. I'm using a CreateView because I have the comments form on the same page as the paginated comments.

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模板(主模板)的相关部分

The relevant parts of my/index.html template (main template)

<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)的相关部分

The relevant parts of 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>

谢谢!

推荐答案

我有同样的问题,并通过在views.py文件中显式添加一个is_ajax检查来修复,例如:

I had the same issue, and fixed it by explicitly adding an is_ajax check in the views.py file, for example:

class MyIndex(CreateView):
    form_class = CommentForm
    template_name = 'my/index.html'
    page_template = 'my/comments.html'

    def get(self, request, *args, **kwargs):
        if request.is_ajax():
            self.template_name = self.page_template
        return super(MyIndex, self).get(request, *args, **kwargs)

    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

你也迁移ht需要使用render / render_to_response而不是返回默认的get方法,这取决于你的页面的结构。

You also might need to use render/render_to_response rather than returning the default get method though, it depends on how your page is structured.

这篇关于无尽的分页加载滚动的整个页面内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆