能否在jsonify(data)返回函数中实现GET POST?

问题描述 投票:0回答:1

我有:

服务器:

@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查询。请告知...我一直在收到方法不允许错误

python post flask get
1个回答
0
投票
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)
© www.soinside.com 2019 - 2024. All rights reserved.