[英]Python decorators and Flask routes: Can I decorate a function call or only a function definition?
我有一个Flask路线:
@app.route('/')
def index():
return render_template('index.html')
我可以在别处定义我的函数并装饰函数调用吗?
from module import index
@app.route('/')
index()
我没有对装饰器的基本掌握,我也不确定是否有关于标准行为的Flask特定内容,所以提前感谢任何澄清。
在这种情况下你不能修饰函数调用,但你可以定义需要调用的新函数:
from module import index
@app.route('/')
def new_index()
return index()
甚至简单,正如@JoranBeasley提出的那样:
app.route("/")(index)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.