route()装饰的URL路径链接到一个回调函数,并增加了一个新的路由默认的应用程序。但是,只有一条路线的应用程。
本实例展示如何添加多个路径:
from bottlepy.bottle import route, run,template
@route('/')
@route('/hello/<name>')
def greet(name='Stranger'):
return template('Hello {{name}}, how are you?', name=name)
run(host='localhost', port=8080, debug=True)
对比一下
from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
run(host='localhost', port=8080, debug=True)

本文介绍使用BottlePy框架实现多路径路由的方法,通过@route装饰器为不同URL路径设置回调函数,演示了如何创建灵活的Web应用程序。
295

被折叠的 条评论
为什么被折叠?



