【问题标题】:django endless pagination(twitter style) not working - .endless_more class not in html but used in jsdjango 无休止的分页(twitter 风格)不起作用 - .endless_more 类不在 html 中但在 js 中使用
【发布时间】:2012-10-17 19:37:48
【问题描述】:

我正在使用 django endless pagination 。它工作正常,只显示底部的数字。

但是,我尝试将 twitter 风格融入其中:

http://django-endless-pagination.readthedocs.org/en/latest/twitter_pagination.html#pagination-on-scroll

我完全按照但没有工作。

当我查看js代码时,我看到他们在js类中使用了.endless_more,但是生成的html文件只有两个链接类:

1)endless_page_current
2)endless_page_link

但他们在js 中使用了a.endless_more

你能告诉我正确的实现方式吗?

谢谢

观看次数:

from endless_pagination.decorators import page_template
@page_template("my_index_page.html")
def myview(request,template='my_index.html', extra_context=None):
  data = {}
 if extra_context is not None:
     data.update(extra_context)

 myobj = Myobj.objects.all()
 data['myobj'] = myobj
 return render_to_response(template, data, context_instance=RequestContext(request))

模板:

my_index.html

 <script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="{{ STATIC_URL }}js/endless.js"></script>
<script src="{{ STATIC_URL }}js/endless_on_scroll.js"></script>
 {% include page_template %}

my_index_page.html

 {% load templatetags %}
<center>
<div>
{% load endless %}
{% paginate myobj %}
{% for obj in myobj %}

 {{  obj.name }}


 {% endfor %}

 {% show_pages %}

  </div> 
 <center>

在这里,我认真地相信我需要添加一些类,例如 django-endless-documentation 错过的 endless_more 。

【问题讨论】:

  • 我建议你也应该发布视图和模板代码。
  • 告诉我一件事,真的有用吗?如果是的话,如果我犯了任何错误,我会重新检查
  • 什么有效?无休止的分页(推特分页)?是的,它确实。我一直在我的项目中使用它
  • @Jonathan 我添加了代码,请看。

标签: python django django-pagination


【解决方案1】:

我在我的门户上使用它,你的代码看起来不错,你只是错过了一件事

{% show_more %}

这就是真正启用 twitter 式无限分页的原因

在这里编辑:

你也可以添加这个:

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

其中“20”是触发滚动的像素数(从页面底部算起)

您可能想尝试不止一种价值,直到获得适合您项目的完美价值

herehere

【讨论】:

  • 是否有任何配置来限制更多页面的最大数量?此外,仅当我们位于页面结束的底部时才应发送 ajax 请求。所以,在这个地方,当我们滚动时,它应该显示新结果,但即使我在页面顶部,只要我滚动鼠标,它就会获取新结果
  • 为您的第二个问题编辑了我的答案。您可能要显示的页面数在视图内处理,否则infinite_scroll 将继续运行,直到有页面要显示。
  • @SamueleMattiuzzo:需要一些帮助,我不想显示链接以在向下滚动时加载新页面时显示更多页面,如何隐藏该链接?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-03
  • 1970-01-01
相关资源
最近更新 更多