title: django download csv file using a link
body: <p>I am a new to django and python. Need some guidance in this quest.</p>
  
  <p>Case: When the user hits the submit button on a form, it should display Success page and a link where they can download the results. The results are in excel file. I can create output to excel file using xlwt module and display the success page individually but not both at the same time. </p>
  
  <p>What i have:
  I am running django1.1.1 on windows XP with python 2.6. There was similar question asked 
   but was not able to make it work.</p>
  
  <p>my success page.html has this line</p>
  
  <pre><code>&lt;a href="../static/example.xls"&gt;Download CSV File&lt;/a&gt;
  </code></pre>
  
  <p>urls.py:</p>
  
  <pre><code>url(r'^static/(?P&lt;path&gt;.*)$', send_file), 
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>def send_file(request):
  
  import os, tempfile, zipfile
  from django.core.servers.basehttp import FileWrapper
  
  """                                                                         
  Send a file through Django without loading the whole file into              
  memory at once. The FileWrapper will turn the file object into an           
  iterator for chunks of 8KB.                                                 
  """
  filename = "C:/example.xls" # Select your file here.                                
  wrapper = FileWrapper(file(filename),"rb")
  response = HttpResponse(wrapper, content_type='text/plain')
  #response['Content-Length'] = os.path.getsize(filename)
  return response
  </code></pre>
  
  <p>When i click on the link, it gives path error</p>
  
  <pre><code>send_file() got an unexpected keyword argument 'path'
  Request Method: GET
  Request URL:    localhost:8000/webinput/static/example.xls
  Exception Type: TypeError
  Exception Value:    
  send_file() got an unexpected keyword argument 'path'
  </code></pre>
  
  <p>BTW example.xls is at both the locations C:/example.xls and in static folder</p>
  
  <p>Structure:</p>
  
  <ul>
  <li>webdb
  
  <ul>
  <li>Static
  
  <ul>
  <li>example.xls</li>
  </ul></li>
  <li>Webinput
  
  <ul>
  <li>urls.py</li>
  <li>views.py</li>
  <li>models.py</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>I have these 2 modules as well. If i use backup_to_csv it works fine but it downlods directly without the link. How to do the same when i already have a file. If there are other ways where i dont have to store file, that is fine too.</p>
  
  <p>def xls_to_response(xls, fname):</p>
  
  <pre><code>response = HttpResponse(mimetype="application/ms-excel")
  response['Content-Disposition'] = 'attachment; filename=%s' % fname
  xls.save(response)
  return response
  </code></pre>
  
  <p>def backup_to_csv(request,row):</p>
  
  <pre><code>response = HttpResponse(mimetype='text/csv')
  response['Content-Disposition'] = 'attachment; filename="backup.csv"'
  writer = csv.writer(response, dialect='excel')    
  #code for writing csv file go here...
  for i in row:
      writer.writerow(i)
  return response
  </code></pre>