为什么要使用通用视图执行此操作?没有通用视图,很容易做到这一点:
from django.http import HttpResponsedef song_download(request, song_id): song = Song.objects.get(id=song_id) fsock = open('/path/to/file.mp3', 'r') response = HttpResponse(fsock, content_type='audio/mpeg') response['Content-Disposition'] = "attachment; filename=%s - %s.mp3" % (song.artist, song.title) return response我不确定是否可以通过通用视图以某种方式使这项工作可行。但无论哪种方式,在这里使用一个都是多余的。如果没有要呈现的模板,则通用视图自动提供的上下文是无用的。



