bottle-beaker icon indicating copy to clipboard operation
bottle-beaker copied to clipboard

How am I supposed to use this module?

Open yoooooooooooooooooooooooo opened this issue 6 years ago • 4 comments

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

signalw avatar Jul 29 '18 04:07 signalw

Hello, same for me AttributeError: 'NoneType' object has no attribute 'get' Linux centos + python 3.6

dorel14 avatar Aug 05 '19 14:08 dorel14

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.

defnull avatar Aug 05 '19 17:08 defnull