如何在Flask中的html文档上使用当前_user.field
我正在尝试将{current_user.plan}或{{form.plan.data}添加到我的html文档中,以显示用户当前所在的计划。此代码适用于我的第一个表,但不适用于第二个表中“计划”字段所在的任何字段 我有一张预订表,用户可以在其中选择他们的计划:如何在Flask中的html文档上使用当前_user.field,flask,flask-sqlalchemy,flask-wtforms,Flask,Flask Sqlalchemy,Flask Wtforms,我正在尝试将{current_user.plan}或{{form.plan.data}添加到我的html文档中,以显示用户当前所在的计划。此代码适用于我的第一个表,但不适用于第二个表中“计划”字段所在的任何字段 我有一张预订表,用户可以在其中选择他们的计划: @app.route("/book", methods=['GET', 'POST']) def book(): form = BookingForm() if form.validate_on_submit():
@app.route("/book", methods=['GET', 'POST'])
def book():
form = BookingForm()
if form.validate_on_submit():
acct = AccountInformation(plan=form.plan.data, firstname=form.firstname.data,
lastname=form.lastname.data, dob=form.dob.data, address=form.address.data,
suburb=form.suburb.data, postcode=form.postcode.data, state=form.state.data,
phone=form.phone.data, user_id=current_user.userid)
db.session.add(acct)
db.session.commit()
flash(f'Thanks {form.firstname.data}! You are now registered for the {form.plan.data}
plan! Please check your '
f'email for more information next steps ', 'success')
return redirect(url_for('home'))
return render_template('book.html', title='Book', form=form, plan=plan)
上面的代码工作得非常好,甚至会闪烁form.plan.data
但是,我正在尝试使用html在我的帐户页面上显示form.plan.data:
@app.route("/account", methods=['GET', 'POST'])
@login_required
def account():
form = UpdateAccountForm()
if form.validate_on_submit():
if form.picture.data:
picture_file = save_picture(form.picture.data)
current_user.image_file = picture_file
current_user.username = form.username.data
current_user.email = form.email.data
db.session.commit()
flash('Your account has been updated!', 'success')
return redirect(url_for('account'))
elif request.method == 'GET':
form.username.data = current_user.username
form.email.data = current_user.email
image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
return render_template('account.html', title='Account', image_file=image_file, form=form)
这是html文档上的代码:
<div class="column" style="background-color: #24252a;">
<h2>Membership Plan</h2><br>
<p>Current Plan: {{ form.data.plan }}</p>
</div>
会员计划
当前计划:{form.data.Plan}
如果你有任何问题,请告诉我。任何帮助都将不胜感激:)