bottle-beaker
bottle-beaker copied to clipboard
How am I supposed to use this module?
The example doesn't work:
import bottle
from bottle.ext import beaker
session_opts = {
'session.type': 'file',
'session.cookie_expires': 300,
'session.data_dir': './data',
'session.auto': True
}
app = beaker.middleware.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)
s
is always None
and I don't understand why...
Exception:
AttributeError("'NoneType' object has no attribute 'get'",)
That's weird. I tried your exact same code and didn't run into any problems. Worked on both python2.7 and python3.6
Hello, same for me AttributeError: 'NoneType' object has no attribute 'get' Linux centos + python 3.6
If s
is None, then beaker middleware did not inject the session object. The example code actually does not use this plugin, but directly applies the beaker session middleware to the whole bottle application.