Skip to content

Instantly share code, notes, and snippets.

@borgle
Last active March 30, 2017 07:57
Show Gist options
  • Save borgle/22d1f4bb9ede94d4654dcb141d155d88 to your computer and use it in GitHub Desktop.
Save borgle/22d1f4bb9ede94d4654dcb141d155d88 to your computer and use it in GitHub Desktop.
bottle sample code & module seperated & beaker sesson middleware
#!/usr/bin/env python
# coding:utf-8
__version__ = '1.0.0'
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from gevent import monkey
monkey.patch_all()
import bottle
from beaker.middleware import SessionMiddleware
session = {
'session.type': 'file', # memory, ext:memcached, ext:mysql ....
'session.cookie_expires': 300,
'session.data_dir': './data',
'session.auto': True
}
main_app = bottle.Bottle()
sub_app = bottle.Bottle()
end_app = bottle.Bottle()
app = SessionMiddleware(main_app, session)
@main_app.route('/')
def index():
return 'This is app'
@sub_app.route('/')
def sub_app_index():
time.sleep(2)
return 'This is subapp'
@end_app.route('/')
def end_app_index():
time.sleep(3)
return 'This is endapp'
@end_app.route('/last')
def last_app_index():
time.sleep(5)
return 'This is lastapp'
main_app.mount('/sub', sub_app)
sub_app.mount('/end', end_app)
bottle.run(app=app, server='gevent', reloader=True, debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment