title: Django pagination - How to limit the pages?
body: <p>I'm using this code to display the pagination on my page</p>
  
  <pre><code>            &lt;ul class="pagination pagination-sm"&gt;
                  {% if restaurants.has_previous %}
                      &lt;li&gt;&lt;a href="?page={{ restaurants.previous_page_number }}"&gt;Prev&lt;/a&gt;&lt;/li&gt;
                  {% endif %}
                  {% for page in restaurants.paginator.page_range %}
                      &lt;li class="{% if restaurants.number == page %}active{% endif %}"&gt;&lt;a
                              href="?page={{ page }}"&gt;{{ page }}&lt;/a&gt;&lt;/li&gt;
                  {% endfor %}
  
                  {% if restaurants.has_next %}
                      &lt;li&gt;&lt;a href="?page={{ restaurants.next_page_number }}"&gt;Next&lt;/a&gt;&lt;/li&gt;
                  {% endif %}
              &lt;/ul&gt;
  </code></pre>
  
  <p>The issue is that the code above shows all page like this:</p>
  
  <pre><code>1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | and so on..
  </code></pre>
  
  <p>Instead I would like to show something like this:</p>
  
  <pre><code>1 | 2 | 3 | 4 | 5
  </code></pre>
  
  <p>How can I do that? </p>
  
  <p>This is my view:</p>
  
  <pre><code>def listing(request):
      list_restaurants = ShopAccount.objects.filter(is_active=1)
      # only active products
      paginator = Paginator(list_restaurants, 20)  # Show 20 products per page
  
      page = request.GET.get('page')
      try:
          restaurants = paginator.page(page)
      except PageNotAnInteger:
          # If page is not an integer, deliver first page.
          restaurants = paginator.page(1)
      except EmptyPage:
          # If page is out of range (e.g. 9999), deliver last page of results.
          restaurants = paginator.page(paginator.num_pages)
  
      return render_to_response('restaurants/list.html', {'restaurants': restaurants}, context_instance=RequestContext(request))
  </code></pre>