[英]Before_request for multiple Blueprints
Here's my situation: 这是我的情况:
Let's say I have 2 Blueprints before_request method: 假设我有2个蓝图before_request方法:
mod = Blueprint('posts', __name__, url_prefix='/posts')
@mod.before_request
def before_request():
#some code that uses SQLAlchemy here
pass
Now I don't want to duplicate the logic in this method in the second blueprint. 现在我不想在第二个蓝图中复制此方法中的逻辑。
How can I do this? 我怎样才能做到这一点?
PS: I'm new to Python so I might be missing something obvious. PS:我是Python的新手,所以我可能会遗漏一些明显的东西。 Thanks.
谢谢。
使用blueprint.before_app_request
,它适用于应用程序范围内的视图,而不仅仅适用于同一蓝图中的视图
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.