After digging into the beaker source code a little, finally I found the way.
Use the decorator this way:
@app1.wrap_app.route('/test')
def test():
return 'OK'
Question
The documentation of Bottle show how to use beaker for session management, like the following
import bottle
from beaker.middleware import SessionMiddleware
session_opts = {
'session.type': 'file',
'session.cookie_expires': 300,
'session.data_dir': './data',
'session.auto': True
}
app = SessionMiddleware(bottle.app(), session_opts)
@bottle.route('/test')
def test():
s = bottle.request.environ.get('beaker.session')
s['test'] = s.get('test',0) + 1
s.save()
return 'Test counter: %d' % s['test']
bottle.run(app=app)
My problem is, I have multiple bottle applications, and each of them serves a virtual host (that is powered by cherrypy). So I can not use decorate "@bottle.route", instead, I need to use decorate like "app1.route('/test')" , "app2.route('/test')" .
But if I warp app with Beaker middleware, like the following,
app1= Bottle()
app2= Bottle()
app1 = SessionMiddleware(app1, session_opts)
app2 = SessionMiddleware(app2, session_opts)
when python run to the following ,
@app1.route('/test')
def test():
return 'OK'
it will report error, AttributeError: 'SessionMiddleware' object has no attribute 'route'
That's for sure, because now app1 is actually a 'SessionMiddleware' not a Bottle app.
How to solve that issue?
No correct solution
OTHER TIPS
After digging into the beaker source code a little, finally I found the way.
Use the decorator this way:
@app1.wrap_app.route('/test')
def test():
return 'OK'