在我使用模板继承之前, Django Endless Pagination工作得非常好。
视图.py:
from django.shortcuts import render
def home(request):
objects = range(30)
return render(request,
'index.html',
locals()
)
索引.html:
{% extends "root.html" %}
{% load endless %}
{% paginate objects %}
{% block content %}
{{ objects }}
<br/>
<br/>
{% show_pages %}
{% endblock %}
根.html:
<div class="content">
{% block content %}{% endblock %}
</div>
如果我取消注释{% extends "root.html" %}
index.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 %}