title: Django generate csv file on view and download
body: <p>I have this code:</p>
  
  <pre><code>    with open('stockitems_misuper.csv', 'wb') as myfile:
          wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
          wr.writerows(file_rows)
  
      response = HttpResponse(myfile, content_type='text/csv')
      response['Content-Disposition'] = 'attachment; filename=stockitems_misuper.csv'
      return response
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>I/O operation on closed file</p>
  </blockquote>
  
  <p>How can I send the created csv file to the front end?</p>