title: Django paginator with many pages
body: <p>I have implemented a paginator with the generic ListView. My problem is that for list with many pages it displays all the page numbers instead of for example five pages before and after the current page. Is there an easy way to fix this?</p>
  
  <p>in the views.py:</p>
  
  <pre><code>class CarList(LoginRequiredMixin, ListView):
  model = Car
  paginate_by = 20
  </code></pre>
  
  <p>in the html:</p>
  
  <pre><code>{% if is_paginated %}
          &lt;ul class="pagination pagination-centered"&gt;
              {% if page_obj.has_previous %}
                  &lt;li&gt;&lt;a href="/car?ordering={{ current_order }}&amp;page=1"&gt;&lt;&lt;&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/car?ordering={{ current_order }}&amp;page={{ page_obj.previous_page_number }}"&gt;&lt;&lt;/a&gt;&lt;/li&gt;
              {% endif %}
  
              {% for i in paginator.page_range %}
              &lt;li {% if page_obj.number == i %} class="active" {% endif %}&gt;&lt;a href="/car?ordering={{ current_order }}&amp;page={{i}}"&gt;{{i}}&lt;/a&gt;&lt;/li&gt;
              {% endfor %}
  
              {% if page_obj.has_next %}
                  &lt;li&gt;&lt;a href="/car?ordering={{ current_order }}&amp;page={{ page_obj.next_page_number }}"&gt;&gt;&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="/car?ordering={{ current_order }}&amp;page={{ page_obj.paginator.num_pages }}"&gt;&gt;&gt;&lt;/a&gt;&lt;/li&gt;
              {% endif %}
          &lt;/ul&gt;
  {% endif %}
  </code></pre>