Можно ли реализовать GET POST в функции возврата jsonify (data)? - PullRequest
0 голосов
/ 12 марта 2020

У меня есть:

сервер:

@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 method="post" action ="/indexGetData">
<input type="text" id="userID" name="user_ID">
<input type="submit" value="Search"
</form>

и я хочу получить значения из пользовательской формы в индексе. html шаблон для передачи на запрос sql. Пожалуйста, сообщите ... Я получаю Метод не допускается ошибка

1 Ответ

0 голосов
/ 12 марта 2020
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)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...