上传文件,,<


<!DOCTYPE ><html>    <head>        <title></title>    </head>    <body>        <form method="POST" action="." enctype="multipart/form-data" name="form">{% csrf_token %}        选择文件: <input type="file" name="filename" /> <br />        <input type="submit" value="上传">        </form>    </body></html>------------------------------------------------------------------------------------# -- encoding=utf-8 --import settingsimport os,os.pathfrom service.common.decorator import render_tofrom django.views.decorators.csrf import csrf_exempt@csrf_exempt@render_to("upload.html")def upload_file(request,questionaire,term):    if request.method == 'POST':        getFile = request.FILES['filename']        fname = os.path.basename(getFile.name)        if getFile:            path = os.path.join(settings.MEDIA_ROOT,'report')            fpath = os.path.join(path,fname)            fp = open(fpath,'wb')            for content in getFile.chunks():                fp.write(content)            fp.close()            fpath1 = os.path.join(path,questionaire.id,term.name)            unzip_file(getFile,fpath1)    return locals()#该片段来自于http://byrx.net

评论关闭