如何从 WTForm 获取所有数据?
How to GET all the ALL DATA from WTForm?
**如何使用字典或列表中的单个命令获取 wtf 表单中的所有数据,而无需编写这么多行代码,指定表单中的每个元素并分别获取数据
**
@app.route('/add', methods=['POST', 'GET'])
def add_cafe():
form = CafeForm()
if form.validate_on_submit():
print("True")
cafe_name = form.cafe_name.data
cafe_location = form.cafe_location.data
opening_time = form.opening_time.data
closing_time = form.closing_time.data
coffee_rating = form.coffee_rating.data
wifi_strength_rating = form.wifi_strength_rating.data
power_socket_availability = form.power_socket_availability.data
return render_template('add.html', form=form)
The wtforms
documentation says that that's Form.data
:
A dict containing the data for each field.
换句话说,
@app.route('/add', methods=['POST', 'GET'])
def add_cafe():
form = CafeForm()
if form.validate_on_submit():
data = form.data
print("True", data)
# ...
return render_template('add.html', form=form)
**如何使用字典或列表中的单个命令获取 wtf 表单中的所有数据,而无需编写这么多行代码,指定表单中的每个元素并分别获取数据 **
@app.route('/add', methods=['POST', 'GET'])
def add_cafe():
form = CafeForm()
if form.validate_on_submit():
print("True")
cafe_name = form.cafe_name.data
cafe_location = form.cafe_location.data
opening_time = form.opening_time.data
closing_time = form.closing_time.data
coffee_rating = form.coffee_rating.data
wifi_strength_rating = form.wifi_strength_rating.data
power_socket_availability = form.power_socket_availability.data
return render_template('add.html', form=form)
The wtforms
documentation says that that's Form.data
:
A dict containing the data for each field.
换句话说,
@app.route('/add', methods=['POST', 'GET'])
def add_cafe():
form = CafeForm()
if form.validate_on_submit():
data = form.data
print("True", data)
# ...
return render_template('add.html', form=form)