[英]Flask can a route inherit code from another route?
Is it possible for a flask app route to inherit code from another flask app route? flask 应用程序路由是否可以从另一个 flask 应用程序路由继承代码?
Example例子
@app.route('/')
def home():
# some code
@app.route('/something')
def something():
# inherit code from home function
You could probably write a handler that is called by both functions like this:您可能会编写一个由两个函数调用的处理程序,如下所示:
@app.route('/')
def home():
shared_code()
@app.route('something')
def something():
shared_code()
# other specific code
def shared_code():
print("this is called by both routes")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.