瓶用PGSQL集成
bottle-pgsql的Python项目详细描述
bottle pgsql基于bottle mysql和bottle sqlite。 瓶子pgsql是一个插件,它集成了postgresql和瓶子 申请。它在 请求,将数据库句柄传递给路由回调并关闭 以后再联系。
要自动检测需要数据库连接的路由,插件 搜索需要关键字参数的路由回调 (可配置)并跳过不需要的路由。这就消除了 不需要数据库连接的路由。
结果作为字典返回。
用法示例:
import bottle import bottle_pgsql app = bottle.Bottle() plugin = bottle_pgsql.Plugin('dbname=db user=user password=pass') app.install(plugin) @app.route('/show/:<item>') def show(item, db): db.execute('SELECT * from items where name="%s"', (item,)) row = db.fetchone() if row: return template('showitem', page=row) return HTTPError(404, "Page not found")