title: Django - TypeError: object of type 'NoneType' has no len() occurred while doing Pagination
body: <p><code>TypeError: object of type 'NoneType' has no len()</code> occurs when I'm adding a pagination to a list view. This happened when I clicked <code>next</code> button to go to page 2. It should have two more results to show.</p>
  
  <p>I guess it's because the value of <code>search</code> is wiped or the <code>queryset</code> becomes none somehow, when I click <strong>next (go to page 2)</strong>, then it returns <strong>none</strong>.</p>
  
  <p><strong>Error:</strong>
  <a href="https://i.stack.imgur.com/jJeHh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jJeHh.png" alt="enter image description here"></a></p>
  
  <p><strong>Search Form:</strong>
  <a href="https://i.stack.imgur.com/OobOV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OobOV.png" alt="enter image description here"></a></p>
  
  <p><strong>book/views:</strong></p>
  
  <pre><code>class SearchResultView(generic.ListView):
      template_name = 'book/search.html'
      model = Book
      context_object_name = 'book_list'
      paginate_by = 2
  
      def get_queryset(self):
          queryset = super().get_queryset()
          search = self.request.GET.get('search')
          if search:
              return Book.objects.filter(
                  title__icontains=search
              )
  </code></pre>
  
  <p><strong>book/templates/book.html:</strong></p>
  
  <pre><code>&lt;form class="form-inline my-2 my-lg-0" method="get" action="{% url 'book:search' %}"&gt;{% csrf_token %}
      &lt;input style="font-size: 12px; width: 200px" class="form-control mr-sm-2" name="search" type="search" placeholder="Book Name" aria-label="Search"&gt;
      &lt;button class="btn btn-outline-primary my-2 my-sm-0" type="submit"&gt;Search&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>book/templates/search.html:</strong></p>
  
  <pre><code>&lt;div id="customContents"&gt;
      {% block customContents %}
      {% if book_list %}
      &lt;ul&gt;
          {% for book in book_list %}
          &lt;li&gt;{{ book.title }}&lt;/li&gt;
          {% empty %}
          {% endfor %}
      &lt;/ul&gt;
  
      {% if is_paginated %}
  
      &lt;div class="pagination"&gt;
              &lt;span class="page-links"&gt;
                  {% if page_obj.has_previous %}
                      &lt;a href="?page={{ page_obj.previous_page_number }}"&gt;previous&lt;/a&gt;
                  {% endif %}
                  {% if page_obj.has_next %}
                      &lt;a href="?page={{ page_obj.next_page_number }}"&gt;next&lt;/a&gt;
                  {% endif %}
              &lt;/span&gt;
      &lt;/div&gt;
      {% endif %}
      {% else %}
      &lt;h3&gt; No result found. &lt;/h3&gt;
      {% endif %}
      {% endblock %}
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>book/urls:</strong></p>
  
  <pre><code>app_name = 'book'
  urlpatterns = [
      path('', views.HomePageView.as_view(), name='home'),
      path('search/', views.SearchResultView.as_view(), name='search'),
      path('&lt;slug:slug&gt;/', views.BookDetailView.as_view(), name='detail'),
  ]
  </code></pre>
  
  <p><strong>It only works fine like this:</strong></p>
  
  <pre><code>class SearchResultView(generic.ListView):
      template_name = 'book/search.html'
      model = Book
      context_object_name = 'book_list'
      paginate_by = 2
      queryset = Book.objects.filter(
                  title__icontains='Python'
              )
  </code></pre>