标签:before 括号 post tor add ESS python get name
from flask import Flask, session
app = Flask(__name__)
@app.route("/index")
def index():
return "ok"
if __name__ == '__main__':
app.run()
from flask import Flask, views
app = Flask(__name__)
def t1(func):
def inner(*args,**kwargs):
print("before1")
result = func(*args,**kwargs)
print("after1")
return result
return inner
def t2(func):
def inner(*args,**kwargs):
print("before2")
result = func(*args,**kwargs)
print("after2")
return result
return inner
class Index(views.MethodView):
methods = ["GET","POST"]
decorators = [t1,t2] # 执行额外的装饰器
def get(self):
print("get")
return "GET"
def post(self):
print("post")
return "POST"
app.add_url_rule("/index",view_func=Index.as_view("index"))
# 在CBV中不能使用装饰器形式的路由,只能使用上面这种;
# as_view("index")括号里的是别名;
if __name__ == '__main__':
app.run()
标签:before 括号 post tor add ESS python get name
原文地址:https://www.cnblogs.com/os-linux/p/11907817.html