from TestLaboratory.settings import SOFTWARE_ROOT import os def create_version_file(file, software_name, version_num): file_dir = SOFTWARE_ROOT + software_name + "/" + version_num if not os.path.exists(file_dir): os.makedirs(file_dir) file_path = file_dir + "/" + file.name try: with open(file_path, 'wb') as f: f.write(file.read()) except FileNotFoundError: return {'code': 500, 'msg': "文件上传错误,未找到该文件"} finally: f.close() return {'code': 200, 'file_path': file_path}