简体   繁体   English

使用模板继承时,Django-endless-pagination失败

[英]Django-endless-pagination fails when using template inheritance

Django Endless Pagination works perfectly fine right until I use template inheritance. 在我使用模板继承之前, Django Endless Pagination可以正常工作。

views.py: views.py:

from django.shortcuts import render

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

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

index.html: index.html:

{% extends "root.html" %}

{% load endless %}

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

root.html: root.html:

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

If I uncomment the line {% extends "root.html" %} in index.html it works. 如果我取消注释index.html中的行{% extends "root.html" %} ,它会起作用。 Otherwise I get the following error: 否则会出现以下错误:

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 %}

This line only execute when this template is into a block or this template does not extends to other 仅当此模板放入块中或此模板未扩展到其他模板时,才执行此行

{% load endless %}

Do you install the app in your settings? 您是否在设置中安装了该应用程序?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM