对于“两个世界中最好的”,您可以将S.Lott的解决方案与xsendfile模块:Django生成文件(或文件本身)的路径,但实际文件由Apache/Lightttpd处理。一旦设置了mod_xsendfile,与视图的集成需要几行代码:from django.utils.encoding import smart_str
response = HttpResponse(mimetype='application/force-download') # mimetype is replaced by content_type for django 1.7response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)response['X-Sendfile'] = smart_str(path_to_file)# It's usually a good idea to set the 'Content-Length' header too.# You can also set any other required headers: Cache-Control, etc.return response当然,只有当您控制您的服务器,或者您的托管公司已经设置mod_xsendfile时,这才能工作。编辑:mimetype被Django 1.7的content_type替换response = HttpResponse(content_type='application/force-download'