title: Django: Serving a Download in a Generic View
body: <p>So I want to serve a couple of mp3s from a folder in <code>/home/username/music</code>.  I didn't think this would be such a big deal but I am a bit confused on how to do it using generic views and my own url.</p>
  
  <p>urls.py</p>
  
  <pre><code>url(r'^song/(?P&lt;song_id&gt;\d+)/download/$', song_download, name='song_download'),
  </code></pre>
  
  <p>The example I am following is found in the generic view section of the Django documentations:
  <a href="http://docs.djangoproject.com/en/dev/topics/generic-views/" rel="noreferrer">http://docs.djangoproject.com/en/dev/topics/generic-views/</a> (It's all the way at the bottom)</p>
  
  <p>I am not 100% sure on how to tailor this to my needs.  Here is my views.py</p>
  
  <pre><code>def song_download(request, song_id):
      song = Song.objects.get(id=song_id)
  
      response = object_detail(
          request,
          object_id = song_id,
          mimetype = "audio/mpeg",
      )
      response['Content-Disposition'= "attachment; filename=%s - %s.mp3" % (song.artist, song.title)
  
      return response
  </code></pre>
  
  <p>I am actually at a loss of how to convey that I want it to spit out my mp3 instead of what it does now which is to output a .mp3 with all of the current pages html contained.  Should my template be my mp3?  Do I need to setup apache to serve the files or is Django able to retrieve the mp3 from the filesystem(proper permissions of course) and serve that?  If it do need to configure Apache how do I tell Django that?</p>
  
  <p>Thanks in advance.  These files are all on the HD so I don't need to "generate" anything on the spot and I'd like to prevent revealing the location of these files if at all possible.  A simple /song/1234/download would be fantastic.</p>