title: How to paginate Django with other get variables?
body: <p>I am having problems using pagination in <a href="http://en.wikipedia.org/wiki/Django_%28web_framework%29" rel="noreferrer">Django</a>.  Take the URL below as an example:</p>
  
  <pre><code>http://127.0.0.1:8000/users/?sort=first_name
  </code></pre>
  
  <p>On this page I sort a list of users by their first_name.  Without a sort GET variable it defaults to sort by id.  </p>
  
  <p>Now if I click the next link I expect the following URL:</p>
  
  <pre><code>http://127.0.0.1:8000/users/?sort=first_name&amp;page=2
  </code></pre>
  
  <p>Instead I lose all get variables and end up with </p>
  
  <pre><code>http://127.0.0.1:8000/users/?page=2
  </code></pre>
  
  <p>This is a problem because the second page is sorted by id instead of first_name.</p>
  
  <p>If I use request.get_full_path I will eventually end up with an ugly URL:</p>
  
  <pre><code>http://127.0.0.1:8000/users/?sort=first_name&amp;page=2&amp;page=3&amp;page=4
  </code></pre>
  
  <p>What is the solution?  Is there a way to access the GET variables on the template and replace the value for the page?</p>
  
  <p>I am using pagination as described in <a href="http://docs.djangoproject.com/en/dev/topics/pagination/" rel="noreferrer">Django's documentation</a> and my preference is to keep using it.  The template code I am using is similar to this:</p>
  
  <pre><code>{% if contacts.has_next %}
      &lt;a href="?page={{ contacts.next_page_number }}"&gt;next&lt;/a&gt;
  {% endif %}
  </code></pre>