Re: [bottlepy] [newbie] Can't access bottle_pgsql plugin once mounted

53 views
Skip to first unread message

Marcel Hellkamp

unread,
Nov 9, 2012, 8:16:00 AM11/9/12
to bott...@googlegroups.com
Am 09.11.2012 12:15, schrieb Emmanuel Quevillon:
> import bottle
> import bottle_pgsql
>
> lib = bottle.Bottle()
> libcfg configdict.ConfigDict = ('demult.ini')
> lib.config = libcfg
> lib.TEMPLATE_PATH = [libcfg.get ('tmpl') ['library']]
> pgsql = bottle_pgsql.Plugin ('dbname =' + libcfg.get ('db') ['dbnm'] +
> 'User =' + libcfg.get ('db') ['user'] +
> 'Password =' + libcfg.get ('db') ['pass'] +
> 'Host =' + libcfg.get ('db') ['host'] +
> 'Port =' + libcfg.get ('db') ['port'])
> lib.install (pgsql)
>
> then when I do
>
> @lib.route('/', apply=[pgsql])
> def home(db):
> .....
>
> I get a 500 internal server error without any output from the dev server
> console.

You can skip the "apply=[pgsql]". By app.install()ing a plugin, it is
automatically applied to all routes of that application.

Try enabling debug mode via "bottle.debug(True)" to get meaningful errors.

Emmanuel Quevillon

unread,
Nov 9, 2012, 10:51:13 AM11/9/12
to bott...@googlegroups.com
Hi Marcel,

Thanks for your quick answer.

I get rid of the apply=[pgsql] call.  The view is rendered as wanted. But now, I can access the 'db' attribute to execute pgsql query to the database?

lib.install(pgsql)

@lib.route('/')
@bottle.mako_view('library/home')
def home():
    .....

If I change def home(): to def home(db): then I get the error from bottle :

NameError("global name 'db' is not defined",)

Where as in the documentation it is defined as follow :

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:...

If I try like this

@lib.route('/:id')
@bottle.mako_view('library/home')
def home(id,db):
    print "OK home "
    print id

I get 

TypeError('home() takes exactly 2 arguments (1 given)',)

I'm sorry but I'm really confused, getting my hairs out of my head :(

Thanks 

Emmanuel
Reply all
Reply to author
Forward
0 new messages