Therefore, I want to upload a couple of mp3 files from the folder to /home/username/music . I didnโt think it would be so important, but I got a little confused how to do this using common views and my own URL.
urls.py
url(r'^song/(?P<song_id>\d+)/download/$', song_download, name='song_download'),
The example that I follow is in the general view section of the Django documentation: http://docs.djangoproject.com/en/dev/topics/generic-views/ (below)
I am not 100% sure how to adapt this to my needs. Here is my views.py
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
I'm actually at a loss how to convey that I want him to spit out my mp3 instead of what he is doing now - output .mp3 with all current pages containing html. Should my template be my mp3? Do I need to configure apache to serve files, or can Django extract mp3 from the file system (of course, the appropriate permissions) and maintain it? If you need to configure Apache, how do I tell Django about this?
Thanks in advance. All these files are located on the hard drive, so I donโt need to โgenerateโ anything in place, and I would like to prevent the disclosure of the location of these files, if possible. A simple / song / 1234 / download would be fantastic.
python file django
TheLizardKing
source share