title: django pagination "That page contains no results"
body: <p>I want to use django pagination. The first page is able to load products but the last page is not showing them.</p>
  
  <p>Here is my index view:</p>
  
  <pre><code>def index(request):
  
      categories = Category.objects.filter(parent_category=None)
  
      product_list = Product.objects.filter(is_deleted=False).order_by('created_at')
      paginator = Paginator(product_list, 1) # Show 25 contacts per page
      page = request.GET.get("page",1)
  
      try:
          products = paginator.page(page)
      except PageNotAnInteger:
          products = paginator.page(1)
      except EmptyPage:
          products = paginator.page(1)
  
      context = {
          'products': products,
          'categories': categories
      }
      return render(request, 'product/urunler.html', context)
  </code></pre>
  
  <p>Here is my template:</p>
  
  <pre><code>&lt;div class="blog-pagination"&gt;
      &lt;ul class="flat-pagination style1"&gt;
          {% if products.has_previous %}
              &lt;li class="prev"&gt;
                  &lt;a href="?page={{products.previous_page_number}}" title=""&gt;
                      &lt;img src="{% static 'images/icons/left-1.png' %}" alt=""&gt;Önceki Sayfa
                  &lt;/a&gt;
              &lt;/li&gt;
          {% else %}
              &lt;li class="prev"&gt;
                  &lt;a href="#" title=""&gt;
                      &lt;img src="{% static 'images/icons/left-1.png' %}" alt=""&gt;Önceki Sayfa
                  &lt;/a&gt;
              &lt;/li&gt;
          {% endif %}
          {% for i in products.paginator.page_range %}
              {% if products.number == i %}
                  &lt;li class="active"&gt;
                      &lt;a href="?page={{i}}" class="waves-effect" title=""&gt;{{i}}&lt;/a&gt;
                  &lt;/li&gt;
              {% else %}
                  &lt;li&gt;
                      &lt;a href="?page={{i}}" class="waves-effect" title=""&gt;{{i}}&lt;/a&gt;
                  &lt;/li&gt;
              {% endif %}
          {% endfor %}
          {% if products.has_previous %}
              &lt;li class="next"&gt;
                  &lt;a href="?page={{products.next_page_number}}" title=""&gt;
                      Sonraki Sayfa
                      &lt;img src="{% static 'images/icons/right-1.png' %}" alt=""&gt;
                  &lt;/a&gt;
              &lt;/li&gt;
          {% else %}
          {% if products.has_next %}
              &lt;li class="next"&gt;
                      &lt;a href="" title=""&gt;
                          Sonraki Sayfa
                          &lt;img src="{% static 'images/icons/right-1.png' %}" alt=""&gt;
                      &lt;/a&gt;
              &lt;/li&gt;
          {% endif %}                                                           
          {% endif %}                           
      &lt;/ul&gt;
      &lt;div class="clearfix"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have 2 products in my database I'm able to show the first page but the last page is not showing here is the traceback:</p>
  
  <pre><code>Traceback (most recent call last):
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
  ecommerce_1            |     response = get_response(request)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
  ecommerce_1            |     response = self.process_exception_by_middleware(e, request)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
  ecommerce_1            |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
  ecommerce_1            |   File "/ecommerce/Product/views.py", line 22, in index
  ecommerce_1            |     return render(request, 'product/urunler.html', context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/shortcuts.py", line 30, in render
  ecommerce_1            |     content = loader.render_to_string(template_name, context, request, using=using)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/loader.py", line 68, in render_to_string
  ecommerce_1            |     return template.render(context, request)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/backends/django.py", line 66, in render
  ecommerce_1            |     return self.template.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 207, in render
  ecommerce_1            |     return self._render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 199, in _render
  ecommerce_1            |     return self.nodelist.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 990, in render
  ecommerce_1            |     bit = node.render_annotated(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated
  ecommerce_1            |     return self.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py", line 177, in render
  ecommerce_1            |     return compiled_parent._render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 199, in _render
  ecommerce_1            |     return self.nodelist.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 990, in render
  ecommerce_1            |     bit = node.render_annotated(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated
  ecommerce_1            |     return self.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/loader_tags.py", line 72, in render
  ecommerce_1            |     result = block.nodelist.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 990, in render
  ecommerce_1            |     bit = node.render_annotated(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated
  ecommerce_1            |     return self.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/defaulttags.py", line 322, in render
  ecommerce_1            |     return nodelist.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 990, in render
  ecommerce_1            |     bit = node.render_annotated(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 957, in render_annotated
  ecommerce_1            |     return self.render(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 1040, in render
  ecommerce_1            |     output = self.filter_expression.resolve(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 708, in resolve
  ecommerce_1            |     obj = self.var.resolve(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 849, in resolve
  ecommerce_1            |     value = self._resolve_lookup(context)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/template/base.py", line 911, in _resolve_lookup
  ecommerce_1            |     current = current()
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py", line 158, in next_page_number
  ecommerce_1            |     return self.paginator.validate_number(self.number + 1)
  ecommerce_1            |   File "/usr/local/lib/python3.6/site-packages/django/core/paginator.py", line 50, in validate_number
  ecommerce_1            |     raise EmptyPage(_('That page contains no results'))
  </code></pre>
  
  <p>There is no error in the first page but the last page always comes with errors.</p>