gpt4 book ai didi

javascript - django-el(endless)-pagination 不适用于 AJAX

转载 作者:行者123 更新时间:2023-12-03 02:50:11 24 4
gpt4 key购买 nike

我在我的项目中使用 django-el-pagination(Digg 式分页),但结果似乎没有使用 AJAX。我需要移动页面而不刷新,但ajax似乎无法正常工作。

查看.py

@page_template('dmmactress/actress_dev_page.html')
def actress_dev(request, id, extra_context=None):
instance = get_object_or_404(ActressInfo_two, pk=id)
moviesinfo = ActressinfoMovielist_co.objects.filter(actressinfo_id=id).prefetch_related('movielist').order_by('movielist')

context = {
'actresses': instance,
'moviesinfo':moviesinfo,
}

if extra_context is not None:
context.update(extra_context)

return render(request, 'dmmactress/actress_dev.html', context)

actress_dev.html

        ........
<thead>
</thead>
<tbody id="entries" class="endless_page_template">
{% include page_template %}
</tbody>
........

actress_dev_page.html

{% load el_pagination_tags %}
{% paginate moviesinfos %}
{% for movieinfo in moviesinfo %}
{{ movieinfo.movielist.movie_number|upper }}
{% endfor %}
{% get_pages %}
{% if pages.paginated %}
{{ pages }}
{% endif %}

结果与不使用ajax的默认分页相同。另外,当我单击“页面”链接时,我会转到“/? page = 2”,其中包括刷新整个页面,这不是我想要做的。

并且在 Chrome 控制台上,页面重新加载时不会显示任何日志。 (js文件已成功加载。)

我做错了什么?

最佳答案

需要在文档中添加示例中指定的JS。

https://django-el-pagination.readthedocs.io/en/latest/javascript.html#javascript-pagination-on-scroll

from el_pagination.decorators import page_template

@page_template('myapp/entry_list_page.html') # just add this decorator
def entry_list(request,
template='myapp/entry_list.html', extra_context=None):
context = {
'entry_list': Entry.objects.all(),
}
if extra_context is not None:
context.update(extra_context)
return render(request, template, context)

在模板中

<h2>Entries:</h2>
<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 }}el-pagination/js/el-pagination.js"></script>
<script>$.endlessPaginate({paginateOnScroll: true});</script>
{% endblock %}

关于javascript - django-el(endless)-pagination 不适用于 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47903264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com