2011-02-27 python bottle route
Добавление роута /path с привязкой к методу method:
app.routes.add('path', {'GET': method})
app.routes.routes = filter(lambda x:x.route != 'path', app.routes.routes)
app.routes.compile()
# coding: utf-8
from bottle import get, default_app, run
app = default_app[-1]
#@get(':class_name/:command')
def somecommand(class_name,command):
return 'test route ok: %s %s'% (class_name,command)
@get('/')
def main():
return '''<a href="/add">add route</a><br/>
<a href="/del">del route</a><br/>
<a href="/test/route">test route</a><br/>'''
@get('/add')
def add_r():
app.routes.add(':class_name/:command', {'GET': somecommand})
app.routes.compile()
return 'add ok'
@get('/del')
def del_r():
app.routes.routes = filter(lambda x:x.route != ':class_name/:command',
app.routes.routes)
app.routes.compile()
return 'del ok'
run(host='',port=8080,reloader=True)