views:

41

answers:

2

I have a template showing a list of events. To prepare list of events I'm using generic views, and set 'paginate_by' parameter. Strangely when I load my page I see :

TemplateSyntaxError at /event/latest/
Caught an exception while rendering: 'int' object is not iterable

in 9th line of pagination.html template :

{% if is_paginated %}
{% load i18n %}
<div class="pagination">
    {% if page_obj.has_previous %}
        <a href="?page={{ page_obj.previous_page_number }}{{ getvars }}" class="prev">&lt;&lt; Prev</a>
    {% else %}
        <span class="disabled prev">&lt;&lt; Prev</span>
    {% endif %}
#here {% for page in pages %}
        {% if page %}
            {% ifequal page page_obj.number %}
                <span class="current page">{{ page }}</span>
            {% else %}
                <a href="?page={{ page }}{{ getvars }}" class="page">{{ page }}</a>
            {% endifequal %}
        {% else %}
            ...
        {% endif %}
    {% endfor %}
    {% if page_obj.has_next %}
        <a href="?page={{ page_obj.next_page_number }}{{ getvars }}" class="next">Next &gt;&gt;</a>
    {% else %}
        <span class="disabled next">Next &gt;&gt;</span>
    {% endif %}
</div>
{% endif %}

Here is my view :

def events_nearest(request):
    events = Event.nearest.all()

    return object_list(request,
            queryset = events,
            extra_context = {'title': 'Nearest events'},
            paginate_by = 12,
            template_name = 'event/events_date.html')

And model :

class NearestManager(models.Manager):
    def get_query_set(self):
        return super(NearestManager, self).get_query_set().order_by('-data')

class Event(models.Model):        
    category = models.ForeignKey(Category)
    title = models.CharField(max_length=120)
    slug = models.SlugField(max_length=255, unique=True, verbose_name='Slug')
    about = models.TextField()
    city = models.ForeignKey(City)

    objects = models.Manager()
    nearest = NearestManager()

Any ideas what can cause this ?

A: 

In your error line #9 {% for page in pages %} what exactly is pages

Can't see it in your code anywhere.

chefsmart
strange. The same code worked proviously... thanks for help.
tom_pl
A: 

pages variable is the number of pages, which is int and hence the error: 'int' object is not iterable

you should be looping over page_range

{% for page in page_range %}
Ashok