我想更新个人资料,但是db.session.commit()在IDLE中不起作用,当我尝试使用PythonShell时,它可以工作。我不知道为什么,请帮助我。对不起,我的英语
@app.route('/edit/<username>',methods=['POST','GET'])
@login_required
def edit(username):
form = ProfileForm(request.form)
if request.method=='POST' and form.validate():
t_user = User.query.filter_by(username=username).first()
t_infor = Infor.query.with_parent(t_user).filter_by(user_id=t_user.id).first()
t_infor.phone = form.phone.data
t_infor.mail = form.mail.data
db.session.commit()
return redirect(url_for('profile',username=username))
return render_template('edit.html',form=form,username=username)
@app.route('/profile/<username>')
@login_required
def profile(username):
t_user = User.query.filter_by(username=username).first()
t_infor = Infor.query.with_parent(t_user).filter_by(user_id=t_user.id).first()
ifmt=[{
'name': t_user.name,
'phone':t_infor.phone,
'mail':t_infor.mail
}]
return render_template('profile.html',username=username,ifmt=ifmt)