title: Listview Pagination not working correctly django
body: <p>I'm Django beginner so I'm stuck in class-based pagination and I have followed many posts about pagination but unfortunate couldn't solve this error.</p>
  
  <p>if i search "love" in search box so URL become like this </p>
  
  <blockquote>
    <p><a href="http://127.0.0.1:8000/search/?q=love" rel="nofollow noreferrer">http://127.0.0.1:8000/search/?q=love</a></p>
  </blockquote>
  
  <p>and results show with pagination function but when i click on next pagination button then query get remove and url become like this </p>
  
  <blockquote>
    <p><a href="http://127.0.0.1:8000/search/?page=2" rel="nofollow noreferrer">http://127.0.0.1:8000/search/?page=2</a></p>
  </blockquote>
  
  <p>and error raise: Invalid page (2): That page contains no results</p>
  
  <p>anyone can tell me from where I'm wrong? thanks</p>
  
  <p><strong>Views.py</strong></p>
  
  <pre><code>from django.views import generic
  from .models import Album, Song
  from django.db.models import Q
  
  class Search(generic.ListView):
      template_name = 'music/search.html'
      paginate_by = 5  
  
      def get_queryset(self, *args, **kwargs):
          queryset_list = Song.objects.all()
          query = self.request.GET.get('q')
          if query:
              queryset_list = queryset_list.filter(
                  Q(song_title__icontains=query)|
                  Q(file_type__icontains=query)
                  ).distinct()
          if not query:
              queryset_list = Song.objects.none()
              return queryset_list
          return queryset_list
  </code></pre>
  
  <p><strong>search.html</strong></p>
  
  <pre><code>{% if object_list %}
      &lt;h1&gt;Search result..&lt;/h1&gt;
      {% for i in object_list %}
          &lt;p&gt;{{i.song_title}}&lt;/p&gt;
      {% endfor %}
  
      &lt;!-- pagination--&gt;
      {% if is_paginated %}
            &lt;ul class="pagination"&gt;
              {% if page_obj.has_previous %}
                &lt;li&gt;&lt;a href="?page={{ page_obj.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 paginator.page_range %}
                {% if page_obj.number == i %}
                  &lt;li class="active"&gt;&lt;span&gt;{{ i }} &lt;span class="sr-only"&gt;(current)&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 page_obj.has_next %}
                &lt;li&gt;&lt;a href="?page={{ page_obj.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 %}
      &lt;!-- end pagination--&gt;
  
  {% else %}
      &lt;h1&gt;no result found..&lt;/h1&gt;
  {% endif %}
  </code></pre>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>from django.conf.urls import url
  from music import views
  
  url(r'^search/$', views.Search.as_view(), name='search')
  </code></pre>