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)

 

posted @ 2017-05-11 10:30  风起616  阅读(2674)  评论(0编辑  收藏  举报