title: Removing query string from url in django while keeping GET information
body: <p>I am working on a Django setup where I can receive a url containining a query string as part of a GET. I would like to be able to process the data provided in the query string and return a page that is adjusted for that data but does not contain the query string in the URL.</p>
  
  <p>Ordinarily I would just use <code>reverse()</code>, but I am not sure how to apply it in this case. Here are the details of the situation:</p>
  
  <p><strong>Example URL:</strong> <code>.../test/123/?list_options=1&amp;list_options=2&amp;list_options=3</code></p>
  
  <p><strong>urls.py</strong></p>
  
  <pre><code>urlpatterns = patterns('', 
      url(r'test/(P&lt;testrun_id&gt;\d+)/'), views.testrun, name='testrun')
      )
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def testrun(request, testrun_id):
      if 'list_options' in request.GET.keys():
          lopt = request.GET.getlist('list_options')
          :
          :
          [process lopt list] 
          :
          :
  
      :
      :
      [other processing]
      :
      :
  
      context = { ...stuff... }
      return render(request, 'test_tracker/testview.html', context)
  </code></pre>
  
  <p>When the example URL is processed, Django will return the page I want but with the URL still containing the query string on the end. The standard way of stripping off the unwanted query string would be to return the testrun function with <code>return HttpResponseRedirect(reverse('testrun', args=(testrun_id,)))</code>. However, if I do that here then I'm going to get an infinite loop through the <code>testrun</code> function. Furthermore, I am unsure if the list_options data that was on the original request will still be available after the redirect given that it has been removed from the URL.</p>
  
  <p>How should I work around this? I can see that it might make sense to move the parsing of the list_options variable out into a separate function to avoid the infinite recursion, but I'm afraid that it will lose me the list_options data from the request if I do it that way. Is there a neat way of simultaneously lopping the query string off the end of the URL and returning the page I want in one place so I can avoid having separate things out into multiple functions?</p>
  
  <p>EDIT: A little bit of extra background, since there have been a couple of "Why would you want to do this?" queries.</p>
  
  <p>The website I'm designing is to report on the results of various tests of the software I'm working on. This particular page is for reporting on the results of a single test, and often I will link to it from a bigger list of tests. </p>
  
  <p>The <code>list_options</code> array is a way of specifying the other tests in the list I have just come from. This allows me to populate a drop-down menu with other relevant tests to allow me to easily switch between them.</p>
  
  <p>As such, I could easily end up passing in 15-20 different values and creating huge URLs, which I'd like to avoid. The page is designed to have a default set of other tests to fill in the menu in question if I don't suggest any others in the URL, so it's not a big deal if I remove the <code>list_options</code>. If the user wishes to come back to the page directly he won't care about the other tests in the list, so it's not a problem if that information is not available.</p>