我在 Django 1.6 中使用 django-pagination https://pypi.python.org/pypi/django-pagination 1.0.7 包。我观察到只有当我不使用扩展标签 {% extends "base.html" %}
django-pagination 是否被最新的 Django 破坏或者我在配置中遗漏了一些东西?
项目名称:测试
设置.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',
)
网址.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)),
)
视图.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 %}
主页.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 则分页不起作用。