我有以下代码:
from bottle import response, error, get
import json
@get('/db_Data')
def db_Data(db):
db.execute("SELECT id, name, category, location, date, amount FROM inventory")
names = db.fetchall() # Use db.fetchone() to get results one by one
return json.dumps(names)
@get('/db_Item')
def db_Item(db):
db.execute("SELECT id, name, category, location, date, amount FROM inventory WHERE id=?", (id, ))
names = db.fetchall()
return json.dumps(names)
@error(404)
def error_404_handler(e):
return json.dumps({'Error': {'Message': e.status_line, 'Status': e.status_code}})
if __name__ == "__main__":
from bottle import install, run
from wtplugin import WtDbPlugin, WtCorsPlugin
install(WtDbPlugin())
install(WtCorsPlugin())
run(host='localhost', port=8080, reloader=True, debug=True, autojson=False)
当我想得到一个项目(第二条路线)时,我得到:
InterfaceError: Error binding parameter 0 - probably unsupported type.
第一条路线运转正常。
答案 0 :(得分:2)
您在第二个处理程序中没有任何id
值。您需要在路径中捕获它并将其传递给函数:
@get('/db_Item/<id>')
def db_Item(db, id):
...