我有:
服务器:
@app.route('/')
def index():
return render_template("index.html")
@app.route('/indexGetData', methods=['GET', 'POST'])
def loadData():
if (request.method == 'POST'):
myval = request.form.get('user_ID')
query = "select * from abc where xyz = :myval"
cursor.execute(query, myval=myval)
# convert the result to json
return jsonify(data)
form:
<form method="post">
<input type="text" id="userID" name="user_ID">
<input type="submit" value="Search"
</form>
并且希望从index.html模板中的用户表单获取值以传递到sql查询。请告知...我一直在收到方法不允许错误
query = "select * from abc where xyz = " + str(myval)
data = db.engine.execute(query)
ret= []
for i in data:
ret.append(
{
"key": i.key
}
)
return jsonify(ret)