读书人

django文件下传

发布时间: 2012-12-25 16:18:28 作者: rapoo

django文件上传

        file_obj = request.FILES.get('file', None)    if file_obj:           str_time = time.strftime('%Y-%m-%d_%H_%M_%S')           fname = file_obj.name         #fname = str_time+str(random.randint(0,9999)) + fname[fname.rfind('.'):]        fname = 'my_img'+fname[fname.rfind('.'):]        if os.path.isdir(homedir+'/pub/'+str(users.id)+'/'):            #os.rmdir('C:/hoodbc/')            pass        else :            os.mkdir(homedir+'/pub/'+str(users.id)+'/')        of = open(homedir+'/pub/'+str(users.id)+'/'+fname, 'wb+')           for chunk in file_obj.chunks():               of.write(chunk)           of.close()   


python的文件操作很像linux的命令。

过两天再整合多文件上传的组件,现在先将就着。

读书人网 >编程

热点推荐