这是我的代码:
@app.route('/', methods=['GET', 'POST'])
def index():
form = CryptoForm()
if session.get('currency'):
currency = session.get('currency')
price1 = Get_info(currency)
price = price1.get_filtered_data()
if form.validate_on_submit():
flash('success', 'success')
currency = form.crypto.data
get_price = Get_info(currency)
session['currency'] = get_price.get_filtered_data()
return redirect(url_for('index'))
return render_template("index.html", form=form, price=price)
我正在尝试做的是让用户在表单中键入一个加密的首字母缩写词并提交。用户提交时,它应该显示价格。但是,当页面首次加载时,没有价格,因此price=price
inrender_template
给我错误。我如何解决这个问题,以便仅在他提交表格后才有价格?
如果要提交表单或不提交表单,您想做其他事情,请检查表单是什么method
。
from flask import request
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
# The user submitted something.
else:
# The user fetched something.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句