我有一个连接到 MySQL 数据库的烧瓶应用程序。
笔记
数据库名称 = 评估
表名 = 评估
列 = eval_id、eval_name、日期
我有一个“评估表”,其中包含字段 eval_id、eval_name 和日期。
mysql> use evaluation;
mysql> describe evaluation;
+-----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| eval_id | int(11) | NO | PRI | NULL | |
| eval_name | varchar(20) | NO | | NULL | |
| date | datetime(6) | NO | | NULL | |
+-----------+-------------+------+-----+---------+-------+
如何编写 API 以通过其 id 获得特定评估?我试过下面的,但它不起作用。
@app.route('/getEval/<int:eval_id>', methods=['GET'])
def getEvalByID(eval_id):
cur.execute('''select * from evaluation.evaluation where eval_id=eval_id''')
res = cur.fetchall()
return jsonify({'test':str(res)})
我怎样才能纠正这个问题,并只获得基于 app.route 中提到的 eval_id 的评估。
您需要将 eval_id 不是作为字符串而是作为 VAR 放置。
@app.route('/getEval/<int:eval_id>', methods=['GET'])
def getEvalByID(eval_id):
cur.execute('select * from evaluation.evaluation where eval_id=' + str(eval_id))
res = cur.fetchall()
return jsonify({'test':str(res)})
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句