title: Django/Mezzanine/Cartridge: Providing Non-HTML Download
body: <p>An authenticated user has some digital content under account page and should be able to download it. I do not want to provide a direct HTML link but just deliver the file on clicking download. I have looked at:</p>
  
  <p><a href="http://www.djangobook.com/en/2.0/chapter13.html" rel="nofollow noreferrer">Django Book: Chapter 13</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3213060/django-download-file-not-working">Django download file not working</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3141682/django-download-file-empty">Django download file empty</a></p>
  
  <p>which seem to be relevant solutions and have worked for others. What I see however is that, it seems to be doing the right thing in the sense that:
    - Firstly, there are no errors printed or crashes
    - Dumping out the HttpResponse that is generated to stdout, shows presence of binary data.</p>
  
  <p>But it doesn't download anything, nor does the browser ask if the user thinks this is safe content to download as would if you were downloading some PDF from a website.</p>
  
  <p>I am inclined to think, it could be a settings.py issue that is set as a security measure that might not allow the download. But it could be anything else. </p>
  
  <p>Here is an example of what I have:</p>
  
  <pre class="lang-py prettyprint-override"><code>filePath = os.path.abspath('static/media/files/' + fileName)
  wrapper = FileWrapper(open(filePath), 'r')
  contentType = mimetypes.guess_type(filePath)[0]
  response = HttpResponse(wrapper, content_type = contentType)
  response['Content-Length'] = os.path.getsize(filePath)
  response['Content-Disposition'] = 'attachment; filename=%s/' % smart_str(os.path.basename(filePath))
  
  return response
  </code></pre>
  
  <p>Other things I have tried:</p>
  
  <pre class="lang-py prettyprint-override"><code>with open(filePath, 'rb') as f:
      return HttpResponse(f.read(), mimetype='image/jpeg')
  </code></pre>
  
  <p>Python: 2.7.4</p>
  
  <p>Pip freeze:</p>
  
  <pre><code>Cartridge==0.8.2
  Django==1.5.4
  Fabric==1.8.0
  Mezzanine==1.4.16
  PIL==1.1.7
  Pillow==2.2.1
  Pillow-PIL==0.1dev
  South==0.8.2
  argparse==1.2.1
  bleach==1.2.2
  cartridge-stripe==0.1.3
  distribute==0.6.34
  django-zebra==0.4.3
  ecdsa==0.9
  filebrowser-safe==0.2.30
  grappelli-safe==0.2.22
  gunicorn==18.0
  html5lib==0.95
  oauthlib==0.6.0
  paramiko==1.12.0
  pisa==3.0.33
  psycopg2==2.5.1
  pycrypto==2.6
  pytz==2013.7
  requests==1.2.3
  requests-oauthlib==0.3.3
  stripe==1.9.6
  wsgiref==0.1.2
  </code></pre>