django-endless-pagination无限滚动

时间:2012-08-15 20:10:21

标签: jquery python django infinite-scroll django-endless-pagination

我是Django和Python的新手。我试图在HTML页面上实现无限滚动,但似乎无法搞清楚。我正在使用django-endless-pagination模块,并从here

获取twitter风格(带滚动分页)

我已经安装了django-endless-pagination,在我的settings.py文件中添加了请求上下文处理器,并在settings.py文件中的installed_apps中添加了endless_pagination。

我可以分页,但似乎无法弄清楚如何进行无限滚动。

我的views.py是:

from endless_pagination.decorators import page_template
from models import PeoplePerson
from django.shortcuts import render_to_response, RequestContext

@page_template("people/entry_index_page.html") # just add this decorator
def entry_index(request, template="people/entry_index.html",
    extra_context=None):
    context = {
        'objects': PeoplePerson.objects.all(),
    }
    if extra_context is not None:
        context.update(extra_context)
    return render_to_response(template, context,
        context_instance=RequestContext(request))

entry_index.html是:

{% extends 'people/entry_index_page.html' %} {# is this line right????? #}
{% block js %}
   {% {{ block.super }} %}
    <script src="/mypathto/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="/mypathto/endless.js" type="text/javascript" charset="utf-8"></script>
    <script src="/mypathto/endless_on_scroll.js" type="text/javascript" charset="utf-8"></script>

    <script type="text/javascript" charset="utf-8">
    var endless_on_scroll_margin = 20;
    </script>
{% endblock %}

<h2>Entries:</h2>
{% include page_template %}

和entry_index_page.html是:

{% load endless %}
{% paginate objects %}
{% for object in objects %}
 {{ object.name|upper }} <br>   
{% endfor %}
{% show_more %}

更新:通过在entry_index.html中添加“{%extends'people / entry_index_page.html'%}”,我能够克服“'BlockNode'对象没有属性'上下文'”错误。不确定这是不是正确的方法...我无法在任何地方的文档中找到它,只是从另一个问题提出来。

1 个答案:

答案 0 :(得分:0)

我明白了: 1.设置我的media_root和media_url并确保javascript正常工作