@get和@post

    要把一个函数映射为一个URL处理函数,我们先定义 @get()

    def get(path):

    '''

    Define decorator @get('/path')

    '''

    def decorator(func):

    @functools.wraps(func)

    def wrapper(args, **kw):

    return func(
    args, **kw)

    wrapper.method = 'GET'

    wrapper.route = path

    return wrapper

    return decorator

    这样,一个函数通过 @get() 的装饰就附带了URL信息。

    @post @get 定义类似。