请提供关于如何在我使用flask python创建的搜索框中添加搜索功能的建议。
此外,我想使用python flask和SQLAlchemy在我的数据库中编辑一些信息,并使用此代码。请帮我纠正。
def edit (id):
users = User.query.get(id)
if request.method == 'POST':
name = request.form['name']
phone_number = request.form['phone_number']
email = request.form['email']
address = request.form['address']
table = request.form['table']
user_reg = User(name,phone_number,email,address,table)
db.session.append(user_reg)
db.session.commit()
flash ('Edited')
return redirect(url_for('dashboard'))
return render_template('edit.html', users=users)
答案 0 :(得分:0)
这是最终有效的代码
@app.route('/edit/<id>', methods=['POST', 'GET'])
@login_required
def edit (id):
users = User.query.get(id)
if request.method == 'POST':
users.name = request.form['name']
users.phone_number = request.form['phone_number']
users.email = request.form['email']
users.address = request.form['address']
users.table = request.form['table']
db.session.add(users)
db.session.commit()
flash ('Edited')
return redirect(url_for('dashboard'))
return render_template('edit.html', users=users, id=id)