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()