def post(self): # 获取数据 args = parser.parse_args() username = args.get('username') password = args.get('password') phone = args.get('phone') bobby = args.get('hobby') print(bobby) icon = args.get('icon') print(icon) # 创建user对象 user = User() user.username = username user.password = password if icon: upload_path = os.path.join(Config.UPLOAD_ICON_DIR, icon.filename) icon.save(upload_path) # 保存路径个 user.icon = os.path.join('upload/icon', icon.filename) if phone: user.phone = phone db.session.add(user) db.session.commit() return user
def post(self): args = parser.parse_args() username = args.get('username') password = args.get('password') phone = args.get('phone') hobby = args.get('hobby') icon = args.get('icon') user = User() if icon: upload_path = os.path.join(config.UPLOAD_ICON_DIR, icon.filename) icon.save(upload_path) user.icon = config.UPLOAD_ICON_DIR + '\\' + icon.filename user.username = username user.password = password user.phone = phone db.session.add(user) db.session.commit() return user
def post(self): # 获取数据 args = parser.parse_args() username = args.get('username') password = args.get('password') phone = args.get('phone') hobby = args.get('hobby') # ['篮球', '皮球'] icon = args.get('icon') # <FileStorage: 'gjjxj.jpg' ('image/jpeg')> # 创建user对象 user = User() user.username = username user.password = password if icon: upload_path = os.path.join(Config.UPLOAD_ICON_DIR, icon.filename) icon.save(upload_path) # 保存路径 user.icon = os.path.join('upload', 'icon', icon.filename) if phone: user.phone = phone db.session.add(user) db.session.commit() return user