【问题标题】:infinite scroll with django-endless-pagination带有 django-endless-pagination 的无限滚动
【发布时间】:2012-08-15 20:10:20
【问题描述】:

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

选择 twitter 样式(滚动分页)

我已经安装了 django-endless-pagination,在我的 settings.py 文件中添加了请求上下文处理器,并在我的 settings.py 文件中的 installed_apps 中添加了 never_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 %}

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

【问题讨论】:

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


    【解决方案1】:

    我想通了: 1. 设置我的 media_root 和 media_url 并确保 javascript 工作

    【讨论】:

      猜你喜欢
      • 2013-04-19
      • 2013-08-07
      • 1970-01-01
      • 2013-03-24
      • 2013-01-18
      • 2012-03-14
      • 2018-06-02
      • 1970-01-01
      • 2015-07-20
      相关资源
      最近更新 更多