【问题标题】:Django-endless-pagination fails when using template inheritance使用模板继承时,Django-endless-pagination 失败
【发布时间】:2012-06-20 08:56:43
【问题描述】:

Django Endless Pagination 在我使用模板继承之前工作得非常好。

views.py:

from django.shortcuts import render

def home(request):
    objects = range(30)

    return render(request,
        'index.html',
        locals()
    )

index.html:

{% extends "root.html" %}

{% load endless %}

{% paginate objects %}
{% block content %}
    {{ objects }}
    <br/>
    <br/>
    {% show_pages %}
{% endblock %}

root.html:

<div class="content">
    {% block content %}{% endblock %}
</div>

如果我在 index.html 中取消注释 {% extends "root.html" %} 行,它就可以工作。否则我会收到以下错误:

Error during template rendering

In template /Users/tuk/Desktop/endlesstest/templates/index.html, error at line 10
Cannot find endless page in context.

1   {% extends "root.html" %}
2   
3   {% load endless %}
4   
5   {% paginate objects %}
6   {% block content %}
7       {{ objects }}
8       <br/>
9       <br/>
10      {% show_pages %}
11  {% endblock %}

【问题讨论】:

    标签: python django django-templates pagination


    【解决方案1】:

    此行仅在此模板进入块或此模板未扩展到其他块时执行

    {% load endless %}

    您是否在设置中安装该应用程序?

    【讨论】:

    • 太好了,就是这样,非常感谢!我将 load endlesspaginate objects 标记移到块中,它可以工作。
    • 哦,实际上只有{% paginate objects %}需要在块中。
    • 是的,块外的所有东西就像模板文件中没有的东西一样,当它扩展到其他模板时
    猜你喜欢
    • 2013-01-18
    • 2016-09-18
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-02
    • 2013-04-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多