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