python bottle学习(一)快速入门

from bottle import (run, route, get, post, put, delete)

# bottle中添加路由的两种方法
# 第一种,使用route装饰器,须要指定method(get, put, delete,delete),
# 若是不指定默认为get 方法
@route('/', method='GET')
def hello():
    return "hello, word!"


# 第二种,直接使用方法名做为路由(须要先导入),此时不须要指定方法名。
@get('/a')
@get('/b') # 同一个方法能够付给过个路由,可是同一个路由付给多个方法的时候只会返回最后个匹配的方法
def hello():
    return "hello, a!"

if __name__ == '__main__':

    # run方法中的reloader是一个很实用的功能,调试的时候修改完代码
    # 服务会自动重启,方便开发。
    run(host='0.0.0.0', port=1234, debug=True, reloader=True)
相关文章
相关标签/搜索