django中的未知和损坏的档案

时间:2014-03-27 09:16:56

标签: python django

这是下载文件的代码,但是当文件下载并打开它们时:the archive is unknown and damaged。能帮我解决一下这个问题,代码是:

def download(request):

    file_name =request.GET.get('file_name', '')
    the_file = "C:\\Users\\CV_Uploads\\uploadfiles\\uploadfiles\\uploaded_files\\1395901478_89_uploadfiles.rar"
    filename = os.path.basename(the_file)
    response = HttpResponse(FileWrapper(open(the_file)),
                           content_type=mimetypes.guess_type(the_file)[0])
    response['Content-Length'] = os.path.getsize(the_file)    
    response['Content-Disposition'] = "attachment; filename=%s" % filename
    return response

1 个答案:

答案 0 :(得分:1)

处理路径时,应使用raw字符串。

使用

the_file = r"C:\Users\CV_Uploads\uploadfiles\uploadfiles\uploaded_files\1395901478_89_uploadfiles.rar"