title: Generating CSV file with Django (dynamic content)
body: <p>Inside my view.py, I have two functions, one that processes input from a form and outputs a filtered list, and another that is supposed to export this list to CSV.</p>
  
  <p>Here is the return of my first function:  </p>
  
  <pre><code>return render_to_response('templateX.html',
  {
   'queryset': queryset,
   'filter_form': filter_form,
   'validated': validated,
  },
   context_instance = RequestContext(request)
   )
  </code></pre>
  
  <p>Here is the exporting function:</p>
  
  <pre><code>def export_to_csv(request):
      # get the response object, this can be used as a stream.
      response = HttpResponse(mimetype='text/csv')
      # force download.
      response['Content-Disposition'] = 'attachment;filename=export.csv'
      # the csv writer
      writer = csv.writer(response)
      qs = request.session['queryset']
      for cdr in qs:
          writer.writerow([cdr['calldate'], cdr['src'], cdr['dst'], ])
      return response   
  </code></pre>
  
  <p>I'm not sure how to get the <strong>queryset</strong> from my first function, which contains a list of the items I want in my CSV and use it in my export_to_csv function. 
  Or would the best way be combining these two functions and have the user click on a checkbox whether he/she wants to download a CSV file.
  Any help would be appreciated.</p>