## page was renamed from MicroProj/2008-01-22 ##language:zh #pragma section-numbers on ::-- ZoomQuiet [<>] <> ## 默许导航,请保留 <> = 防盗下载支持 = {{{jack139 reply-to python-cn@googlegroups.com, to "python-cn:CPyUG" , date Jan 20, 2008 5:19 PM subject [CPyUG:38810] Re: 如何 python实现下载功能 }}} 用django很简单,这是剪的一段,改改就可以用了: {{{ from os.path import splitext ext=splitext(this_file.filename)[1] response = HttpResponse(mimetype='application/octet-stream') response['Content-Disposition'] = 'attachment; filename="%s"' % this_file.filename ## 写文件 try: f = open(settings.UPLOAD_PATH+this_file.file_path,'rb') response.write(f.read()) f.close() except Exception, detail: return HttpResponse('eSYS ERROR read: '+str(detail)) return response }}}