title: Pagination in Python and Django
body: <p>I'm a newbie in Python development. I want to pagination my page in Django. I create a dropdown list for user choose number items want display in view. Ex: When i choose '10' in dropdown list and click submit button then the view display 10 items, but when I click 'next' or 'previous' button then the view display 25 items by default I set when loading items before choose value in dropdown list. Now I want when i click 'next' or 'previous' it will display 10 items look like I chosen in dropdown list. How can I do that. This is my code </p>
  
  <p><strong>view.py:</strong></p>
  
  <pre><code>def listing(request):
      people = Person.objects.all()
      if "dropdown" in request.POST:
          per_page = request.POST["dropdown"]
      else: per_page = 25
      paginator = Paginator(people, per_page)
      page = request.GET.get('page')
      try:
          people = paginator.page(page)
      except PageNotAnInteger:
          people = paginator.page(1)
      except EmptyPage:
          people = paginator.page(paginator.num_pages)
      return render_to_response('crud\index.html', RequestContext(request, {'people': people, 'per_page': per_page}))
  </code></pre>
  
  <p>and this is code file index.html</p>
  
  <pre><code>{% if people %}
  &lt;form method="post"&gt;
      {% csrf_token %}
      &lt;table&gt;
          &lt;p&gt;
              &lt;select name="dropdown"&gt;
                  &lt;option value="5"&gt;5&lt;/option&gt;
                  &lt;option value="10"&gt;10&lt;/option&gt;
                  &lt;option value="15"&gt;15&lt;/option&gt;
                  &lt;option value="20"&gt;20&lt;/option&gt;
              &lt;/select&gt;
          &lt;/p&gt;
          &lt;input type="submit" value="Submit"/&gt;
          &lt;tr&gt;
              &lt;th&gt;Name&lt;/th&gt;
              &lt;th&gt;Phone&lt;/th&gt;
              &lt;th&gt;Age&lt;/th&gt;
          &lt;/tr&gt;
          {% for person in people %}
              &lt;tr&gt;
                  &lt;td&gt;{{ person.name }}&lt;/td&gt;
                  &lt;td&gt;{{ person.phone }}&lt;/td&gt;
                  &lt;td&gt;{{ person.age }}&lt;/td&gt;
                  &lt;td&gt;&lt;a href="delete/{{ person.id }}"&gt;Delete&lt;/a&gt;&lt;/td&gt;
                  &lt;td&gt;&lt;a href="edit/{{ person.id }}"&gt;Edit&lt;/a&gt;&lt;/td&gt;
              &lt;/tr&gt;
          {% endfor %}
          &lt;div class="pagination"&gt;
          &lt;span class="step-links"&gt;
              {% if people.has_previous %}
                  &lt;a href="?page={{ people.previous_page_number }}"&gt;previous&lt;/a&gt;
              {% endif %}
  
              &lt;span class="current"&gt;
                  Page {{ people.number }} of {{ people.paginator.num_pages }}.
              &lt;/span&gt;
  
              {% if people.has_next %}
                  &lt;a href="?page={{ people.next_page_number }}"&gt;next&lt;/a&gt;
              {% endif %}
          &lt;/span&gt;
          &lt;/div&gt;
      &lt;/table&gt;
  &lt;/form&gt;
  {% else %}
      &lt;p&gt;No people in the database&lt;/p&gt;
  {% endif %}
  {% if per_page %}
      &lt;p&gt;You picked {{ per_page }}.&lt;/p&gt;
  {% endif %}
  </code></pre>