Created
January 29, 2013 05:20
-
-
Save alexcabrera/4662006 to your computer and use it in GitHub Desktop.
Example of using beaker sessions with bottle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bottle | |
from beaker.middleware import SessionMiddleware | |
session_opts = { | |
'session.type': 'memory', | |
'session.cookie_expires': 300, | |
'session.auto': True | |
} | |
app = SessionMiddleware(bottle.app(), session_opts) | |
@bottle.route('/') | |
def session_test(): | |
s = bottle.request.environ.get('beaker.session') | |
s['test'] = 'this string came from the session' | |
s.save() | |
bottle.redirect('/output') | |
@bottle.route('/output') | |
def session_output(): | |
s = bottle.request.environ.get('beaker.session') | |
return s['test'] | |
bottle.run( | |
app=app, | |
host='localhost', | |
port=5000, | |
debug=True, | |
reloader=True | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment