title: How to perform pagination for context object in django?
body: <p>I have tried something like this in views.py: </p>
  
  <pre><code>class HomePage(TemplateView):
       template_name = "clouderp/index.html"
  
      def get_context_data(self, **kwargs):
          context = super(HomePage, self).get_context_data(**kwargs) 
          qs = Blog.objects.all()
          context['blog_list'] = qs
  
          page = self.request.GET.get('page')
  
          paginator = Paginator(qs, 4)
  
          try:
              users = paginator.page(page)
          except PageNotAnInteger:
              users = paginator.page(1)
          except EmptyPage:
              users = paginator.page(paginator.num_pages)
  
          context['users'] = users
  
          return context
  </code></pre>
  
  <p>And in template:</p>
  
  <pre><code>{% if users.has_other_pages %}
  &lt;ul class="pagination"&gt;
    {% if users.has_previous %}
      &lt;li&gt;&lt;a href="?page={{ users.previous_page_number }}"&gt;&amp;laquo;&lt;/a&gt;&lt;/li&gt;
    {% else %}
      &lt;li class="disabled"&gt;&lt;span&gt;&amp;laquo;&lt;/span&gt;&lt;/li&gt;
    {% endif %}
    {% for i in users.paginator.page_range %}
      {% if users.number == i %}
        &lt;li class="active"&gt;&lt;span&gt;{{ i }} &lt;span class="sr-only"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
      {% else %}
        &lt;li&gt;&lt;a href="?page={{ i }}"&gt;{{ i }}&lt;/a&gt;&lt;/li&gt;
      {% endif %}
    {% endfor %}
    {% if users.has_next %}
      &lt;li&gt;&lt;a href="?page={{ users.next_page_number }}"&gt;&amp;raquo;&lt;/a&gt;&lt;/li&gt;
    {% else %}
      &lt;li class="disabled"&gt;&lt;span&gt;&amp;raquo;&lt;/span&gt;&lt;/li&gt;
    {% endif %}
  &lt;/ul&gt;
  {% endif %}
  </code></pre>
  
  <p>I have created a blog application using django<br>
  I want to show all my blogs in my main index.html page and also wanted to do pagination for the blogs in my index page...<br>
  I was wondering how to do it...<br>
  Because the process I have done the blogs are not paginated according to 4 at a time...</p>