Python flask代码优化求大神指点,pythonflask,@bp.route(/s
Python flask代码优化求大神指点,pythonflask,@bp.route(/s
@bp.route('/settings/<username>', methods=['GET', 'POST'])@login_requireddef settings(): profile = User.query.get_or_404(username) form = SettingsForm() if form.validate_on_submit(): profile.email = form.email.data profile.location = form.location.data profile.website = form.website.data profile.bio = form.bio.data profile.twitter = form.twitter.data profile.weibo = form.weibo.data profile.github = form.github.data profile.instagram = form.instagram.data db.session.add(profile) db.session.commit() return redirect(url_for('main.index'))
就是那几行profile.xxx = form.xxx.data
直接上代码:
form.populate_obj(profile)
for k in form.__dict__: profile.__dict__[k] = form.__dict__[k].data
编橙之家文章,
相关内容
- 关于Flask中endpoint和blueprint正解解读是什么,flaskendpoi
- Python正则表达式匹配数字问题,python正则表达式,上面是
- 请教Python分割bytes最佳方法,python分割bytes,我有很多b
- Python logging模块如何时将函数执行信息写入文件,,例如
- 请问协程是goto这样理解对吗,协程goto对吗,协程就是
- 用python做微信公众号开发,怎样获取用户到id并跳转到
- 先学习Python之后再学习PHP与java会更好吗,pythonjava,学过
- Python flask实现delete键删除评论用什么方法,pythonflask,后
- Python generator实现同样效果函数是什么,pythongenerator,同
- Python数据类型转换json unicode如何转化为dict,pythonjson,目
评论关闭