title: Display only some of the page numbers by django pagination
body: <p>I am using the django paginator in the template. Its working ok, but not good when there's large numbers of pages.</p>
  
  <p>views.py:</p>
  
  <pre><code>def blog(request):
      blogs_list = Blog.objects.all()
  
      paginator = Paginator(blogs_list, 1)
  
      try:
          page = int(request.GET.get('page', '1'))
      except:
          page = 1
  
      try:
          blogs = paginator.page(page)
      except(EmptyPage, InvalidPage):
          blogs = paginator.page(page)
      return render(request, 'blogs.html', {
          'blogs':blogs
          })
  </code></pre>
  
  <p>snippet of the template:</p>
  
  <pre><code>  &lt;div class="prev_next"&gt;
  
      {% if blogs.has_previous %}
        &lt;a class="prev btn btn-info" href="?page={{blogs.previous_page_number}}"&gt;Prev&lt;/a&gt;
      {% endif %}
      {% if blogs.has_next %}
        &lt;a class="next btn btn-info" href="?page={{blogs.next_page_number}}"&gt;Next&lt;/a&gt;
      {% endif %}
      &lt;div class="pages"&gt;
        &lt;ul&gt;
        {% for pg in blogs.paginator.page_range %}
          {% if blogs.number == pg %}
            &lt;li&gt;&lt;a href="?page={{pg}}" class="btn btn-default"&gt;{{pg}}&lt;/a&gt;&lt;/li&gt;
          {% else %}
            &lt;li&gt;&lt;a href="?page={{pg}}" class="btn"&gt;{{pg}}&lt;/a&gt;&lt;/li&gt;
          {% endif %}
        {% endfor %}
        &lt;/ul&gt;
      &lt;/div&gt;
      &lt;span class="clear_both"&gt;&lt;/span&gt;
  
    &lt;/div&gt; 
  </code></pre>
  
  <p>Now it looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/XUOqG.jpg" alt="enter image description here"></p>
  
  <p>What do I do to display only 7 page numbers and not all of it ranging from the current page number, like this:</p>
  
  <pre><code>Prev 1 (2) 3 4 5 Next
  </code></pre>
  
  <p>I hope I was clear, if not please ask. Your help and guidance will be very much appreciated. Thank you.</p>