我正在编写一个简单的函数,用于将某个文件从服务器下载到我的机器上。该文件由其 id 表示是唯一的。文件正确定位,下载完成,但下载的文件(虽然命名为服务器上的文件)是空的。我的下载功能如下所示:
def download_course(request, id):
course = Courses.objects.get(pk = id).course
path_to_file = 'root/cFolder'
filename = __file__ # Select your file here.
wrapper = FileWrapper(file(filename))
content_type = mimetypes.guess_type(filename)[0]
response = HttpResponse(wrapper, content_type = content_type)
response['Content-Length'] = os.path.getsize(filename)
response['Content-Disposition'] = 'attachment; filename=%s/' % smart_str(course)
return response
我哪里错了?谢谢!