Скачивание файла с сервера
-
Автор: Silver
-
Просмотров: 397
Для скачивания файла есть такая схема:
def get_file_view(request,user_name,fname):
if not request.user.is_authenticated(): return render_to_response('index.html')
import os,mimetypes
file_path=os.getcwd()+UPLOAD_DIR+'/'+user_name+'/'+fname
if os.path.exists(file_path):
with open(file_path,'rb') as fh:
mime=mimetypes.guess_type(file_path)
buf=fh.read()
response=HttpResponse(buf,content_type=mime)
response['Content-Disposition']='attachment; filename='+fname
response['Location']='messages/'
return response
return render_to_response('error.html',{"msg":"Похоже, файл, который Вы запросили, не найден. ;("},
context_instance=RequestContext(request))