0

If I include paginator, then its printing multiple paginator on same page. because I am including in forloop. How do I solve this problem? please help

----------------------
{% autopaginate recipes %}
{% for recipe in recipes %}
  {{ forloop.counter }}
{% endfor %}
-----------

here is my full code.

{% with followers=current_user.get_profile.get_following.all %}
    {% for follower in followers %}
        {% with recipes=follower.recipe_set.all %}
            {% for recipe in recipes %}
                {{ forloop.counter }}
            {% endfor %}
        {% endwith %}
    {% endfor %}
{% endwith %}

Result - > 1 2 3 1 2 3 ...... 50. It should be 53. So I can easily use paginator

thanks

1 Answers1

0

the doc string in the setup.py file of django-pagination mentions the below,

  1. Decide on a variable that you would like to paginate, and use the autopaginate tag on that variable before iterating over it. This could take one of two forms (using the canonical object_list as an example variable):

    {% autopaginate object_list %}

This assumes that you would like to have the default 20 results per page. If you would like to specify your own amount of results per page, you can specify that like so:

   `{% autopaginate object_list 10 %}`

Note that this replaces object_list with the list for the current page, so you can iterate over the object_list like you normally would.

  1. Now you want to display the current page and the available pages, so somewhere after having used autopaginate, use the paginate inclusion tag:

    {% paginate %}

This does not take any arguments, but does assume that you have already called autopaginate, so make sure to do so first.

That's it! You have now paginated object_list and given users of the site a way to navigate between the different pages--all without touching your views.

So, where are you using paginate tag after the autopaginate? You actually need not loop through recipes, autopaginate should do that for you wherever you call paginate.

Parthan
  • 487
  • 4
  • 16
  • thanks for reply. Yes I am including paginate tag first then autopaginate. –  May 03 '12 at 14:39
  • If I use this `{% autopaginate recipes 10 %}`. its displaying first 10 result from first loop and on same page getting 10 more result from second loop. like `1...10 1 ......10` –  May 03 '12 at 14:45