1

django-pagination 的文档对于 1.4 来说已经过时了。关注它们时,我没有收到错误,但分页不起作用。分页页面计数器加载,但没有分页。这是我所拥有的:

settings.py 这里:

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",)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'pagination.middleware.PaginationMiddleware',
)
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',     
    'django.contrib.admin',       
    'django.contrib.admindocs',
    'photologue',
    'pagination',
)

gallery_detail.html 这里:

{% extends "photologue/root.html" %}
{% load pagination_tags %}
{% block title %}{{ object.title }}{% endblock %}

{% block content %}

<h1>Gallery {{ object.title }}</h1>
<h2>Originally published {{ object.date_added|date:"l, F jS, Y" }}</h2>
{% if object.description %}<p>{{ object.description }}</p>{% endif %}
<div class="photo-gallery">

<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    {% autopaginate object.public 10 %}
    {% for photo in object.public %}
    <td><div class="gallery-photo">
        <a href="{{ photo.get_absolute_url }}"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a>
    </div></td>  
    </tr>
</table>
    {% endfor %}
    {% paginate %}
</div>
<p><a href="{% url pl-gallery-list 1 %}">View all galleries</a></p>

{% endblock %}

谢谢您的帮助。

4

2 回答 2

1

你的问题到底是什么,我不确定你在问什么。

我认为 django-pagination 已经两年左右没有维护了。我记得尝试过,但它不起作用,所以我切换到django-endless-pagination并且没有任何问题。您可能需要考虑检查/尝试一下。

于 2012-06-07T22:15:04.020 回答
0

有几个项目可能应该在模板中更正。尝试以下一项或两项:

A. 解决方案可能有效,但可能不是您想要的。

<div class="photo-gallery">

<table border="0" cellspacing="0" cellpadding="0">
  <tr>
    {% autopaginate object.public 10 %}
    {% for photo in object.public %}
    <td><div class="gallery-photo">
        <a href="{{ photo.get_absolute_url }}"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a>
    </div></td>  
    {% endfor %}
    {% paginate %}
    </tr>
</table>
</div>

B. 解决方案 - 如果 A 不起作用,试试这个。

<div class="photo-gallery">

<table border="0" cellspacing="0" cellpadding="0">
    {% autopaginate object.public 10 %}
  <tr>
    {% for photo in object.public %}
    <td><div class="gallery-photo">
        <a href="{{ photo.get_absolute_url }}"><img src="{{ photo.get_thumbnail_url }}" alt="{{ photo.title }}"/></a>
    </div></td>  
    {% endfor %}
    </tr>
    {% paginate %}
</table>    
</div>
于 2012-06-08T14:59:53.323 回答