Django-endless-pagination twitter风格分页不起作用

时间:2015-06-18 08:52:00

标签: django pagination django-templates django-endless-pagination

我正在为我的项目使用django-endless-pagination。但它没有按照预期的那样运作。当我将代码更改为show more模式时,它既不会显示onscroll,也不会显示。

<script>$.endlessPaginate({paginateOnScroll: true});</script>

然而,include标签正在显示模板中的快照。甚至两个脚本(即jquery和endless.js)都在那里。我错过了什么?非常感谢您的帮助和指导。谢谢。

models.py:

class SnapGroup(models.Model):
    name = models.CharField(max_length=150, blank=True, null=True)
    date = models.DateField(default=date.today)

class Snap(models.Model):
    date = models.ForeignKey(SnapGroup)
    image = models.ImageField(upload_to=get_upload_file_name)
    caption = models.CharField(max_length=150, blank=True, null=True)

views.py:

@page_template('snapgroups.html')  # just add this decorator
def snaps(
        request, template='snaps.html', extra_context=None):
    context = {
        'snapgroup': SnapGroup.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(
        template, context, context_instance=RequestContext(request))

snaps.html:

    {% if snapgroup.count > 0 %}

        <div class="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 %}            

    {% else %}
        <li><p>No SNAPGROUP yet!</p></li>
        <span class="clear_both"></span>
    {% endif %}

snapgroups.html:

{% load endless %}

{% paginate snapgroup %}
{% for sg in snapgroup %}
    <h4 id="combination" class="snap_date">{{sg.date|date:'l'}}, {{sg.date}}</h4>
    <ul>
    {% for snap in sg.snap_set.all %}
        <li><a href="{{MEDIA_URL}}{{snap.image}}" data-imagelightbox="f"><img src="{{MEDIA_URL}}{{snap.image}}" alt="{{snap.caption}}" /></a></li>
    {% endfor %}
        <span class="clear_both"></span>
    </ul>
{% endfor %}

{% show_more %}

1 个答案:

答案 0 :(得分:0)

通过此post解决了我的问题。希望这会帮助别人。