Python-装饰器
#例1装饰器
def w1(main_func):
def outer(request,kargs):
print('before')
main_func(request,kargs)
print('after')
return outer
@w1
def show():
print('show')
#1、@w1,执行w1,把自己装饰的函数的函数名当做参数,w1(show)
#2、show函数重新定义,w1(show)返回值
#3、新show=
#例2
def Before1(request,kargs):
print 'before'
def After1(request,kargs):
print 'after'
def Filter(before_func,after_func):
def outer(main_func):
def wrapper(request,kargs):
before_func(request,kargs)
main_func(request,kargs)
after_func(request,kargs)
return wrapper
return outer
@Filter(before,after)
#1、执行@Filter(before,after)
#2、@outer
#3、新Index
def Index(request,kargs):
print 'index'