title: Download a zip file created entirely in memory with Django
body: <p>I need to generate several csv reports, compress and serve as zip to the user. I'm using <a href="https://djangosnippets.org/snippets/365/" rel="nofollow">this snippet</a> as reference </p>
  
  <pre><code>    ...
      temp = StringIO.StringIO()
      with zipfile.ZipFile(temp,'w') as archive:
          for device in devices:
              csv = Mymodel.get_csv_for(device)
              archive.writestr('{}_device.csv'.format(device), str(csv))
  
      response = HttpResponse(FileWrapper(temp), content_type='application/zip')
      response['Content-Disposition'] = 'attachment; filename="devices.zip"')
  
      return response
  </code></pre>
  
  <p>Looking at the <code>archive.listname()</code> i can see the file names.
  Looking at <code>temp.getvalue()</code> i can see some string but when I download the file it comes out empty.</p>