我正在使用Django 1.6的django-pagination https://pypi.python.org/pypi/django-pagination 1.0.7包。我发现只有当我不使用扩展标记{%extends“base.html”%}
时,我的object_list才能正常分页。django-pagination是否被最新的Django打破了,或者我在配置中遗漏了什么?
项目名称:测试
settings.py
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'testing',
'pagination',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'pagination.middleware.PaginationMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.tz',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages',
)
urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^$', 'testing.views.home', name='home'),
url(r'^admin/', include(admin.site.urls)),
)
views.py
from django.shortcuts import render
def home(request):
return render(request, 'home.html', {
'numbers': range(100),
})
base.html文件
<h1>Hello World</h1>
{% block content%}
{% endblock %}
home.html的
{% comment %}
{% extends "base.html" %}
{% endcomment%}
{% load pagination_tags %}
{% autopaginate numbers 2 %}
{% block content %}
{% paginate %}
<ul>
{% for i in numbers %}
<li>{{ i }}</li>
{% endfor %}
</ul>
{% endblock %}
我确实在
中看到了适当的分页http://127.0.0.1:1234
但如果我从base.html扩展home.html,则分页不起作用。