1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| from bottle import Bottle, run import re
def filter(config): delimiter = config or ',' regexp = r'\d+(%s\d)*' % re.escape(delimiter)
def to_python(match): return map(int, match.split(delimiter)) def to_url(numbers): return delimiter.join(map(str,numbers))
return regexp, to_python, to_url
web = Bottle() web.router.add_filter('idslist',filter)
@web.route('/list/<ids:idslist>')#装饰器中使用了filter的名称 def getsomthing(ids): res='' for i in ids: res+=str(i)+'-' return "hello %s "%res
run(web,port=8088, debug=True, reloader=True)
|