tags:

views:

207

answers:

1

Hi,

This is in my urls.py:

group_info = {
    'queryset': Group.objects.all(),
    'template_object_name': 'groups',
    'paginate_by': 25,
}

And this is the relevant URL: (r'^groups/$', 'django.views.generic.list_detail.object_list', group_info),

And this is my code in the template:

<div class="pagination">
    <span class="step-links">
        {% if groups.has_previous %}
            <a href="?page={{ groups.previous_page_number }}">previous</a>
        {% endif %}

        <span class="current">
            Page {{ groups.number }} of {{ groups.paginator.num_pages }}.
        </span>

        {% if groups.has_next %}
            <a href="?page={{ groups.next_page_number }}">next</a>
        {% endif %}
    </span>
</div>

.. but no pagination information is displayed. I think I am doing this exactly as done in the documentation. Any idea what is wrong?

Thanks.

+4  A: 

You're using the wrong variable names. As the docs say, the variable names are paginator for the paginator object and page_obj for the page.

{% if is_paginated %}
    <div class="pagination">
        <span class="step-links">
            {% if page_obj.has_previous %}
                <a href="?page={{ page_obj.previous_page_number }}">previous</a>
            {% endif %}

            <span class="current">
                Page {{ page_obj.number }} of {{ paginator.num_pages }}.
            </span>

            {% if page_obj.has_next %}
                <a href="?page={{ page_obj.next_page_number }}">next</a>
            {% endif %}
        </span>
    </div>
{% endif %}
piquadrat
Thanks. I see what I missed in the docs.
John