我正在尝试使用bottle.py连接mysql,但它显示错误

时间:2013-07-09 13:02:39

标签: python python-2.7 mysql-python bottle

我点了这个链接:“https://pypi.python.org/pypi/bottle-mysql/0.1.1

和“http://bottlepy.org/docs/dev/

这是我的py文件:

import bottle
from bottle import route, run, template
import bottle_mysql

app = bottle.Bottle()
# # dbhost is optional, default is localhost
plugin = bottle_mysql.Plugin(dbuser='root', dbpass='root', dbname='delhipoc')
app.install(plugin)
@route('/hai/<name>')

def show(name,dbname):
    dbname.execute('SELECT id from poc_people where name="%s"', (name))
    print "i am in show"
    return template('<b>Hello {{name}}</b>!',name=name)

run(host='localhost', port=8080)       

这是我的代码,它会抛出错误:

Traceback (most recent call last):
File "C:\Python27\lib\site-packages\bottle.py", line 764, i
return route.call(**args)
File "C:\Python27\lib\site-packages\bottle.py", line 1575,
rv = callback(*a, **ka)
TypeError: show() takes exactly 2 arguments (1 given)

请帮帮我

2 个答案:

答案 0 :(得分:0)

不熟悉bottle-mysql,但在您提供的示例中:

@app.route('/show/:<tem>')

在您的代码中:

@route('/hai/<name>')

可能会发生:

@route('/hai/:<name>')

答案 1 :(得分:0)

简单。改变这一行:

def show(name,dbname):

到此:

def show(name, delhipoc):

更好的是,使用dbname = 'db'然后

def show(name, db):

MySQL插件为其db名称参数选择了一个不幸的名称。将它称为db_parameter_name之类的东西会更加清晰,因为它实际上指的是装饰Python函数中db参数的 name