【发布时间】:2017-05-01 15:15:31
【问题描述】:
使用 WTForms、SQLAlchemy 我试图让用户从下拉列表中选择一个 Country 关键字,然后从该选择中我们将那个国家的坐标(西、南、东、北)传回到程序。
当choices=GeoKeywords.label 顺利通过该国时,一直坚持如何做到这一点。选择“Albania”将传递值“Albania”。但是如何根据该选择引入西、南、东、北?
数据库表:
GP_DD_GEOKEYWORDS= Table('GP_DD_GEOKEYWORDS', Base.metadata,
Column('VALUE', String(75)),
Column('LABEL', String(75)),
Column('WEST', String(50)),
Column('SOUTH', String(50)),
Column('NORTH', String(50)),
Column('EAST', String(50)))
class GeoKeywords():
s = select([GP_DD_GEOKEYWORDS.c.VALUE, GP_DD_GEOKEYWORDS.c.LABEL])
result = connection.execute(s)
label = [row for row in result]
class ReusableForm(Form):
region = SelectField('Geographic Keyword:', choices=GeoKeywords.label)
@app.route("/editorother", methods=['GET', 'POST'])
@login_required
def editorother():
form = ReusableForm(request.form)
if request.method == 'POST':
region = request.form['region']
if form.validate():
"Do stuff with region and coordinates"
【问题讨论】:
标签: python python-2.7 flask sqlalchemy flask-wtforms