本文介绍了用Flask中的flask实例初始化扩展的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Miguel Grinberg的书《 Flask Web开发》之后,我必须用flask实例初始化很多扩展,这样做的目的是什么?

Following Miguel Grinberg's book Flask web development, I have to initialize alot of exetensions with the flask instance what is the point of doing this?

示例

app = Flask(__name__)
manager = Manager(app)
bootstrap = Bootstrap(app)
moment = Moment(app)

推荐答案

您可以查看每个扩展的来源,以了解它们到底在做什么.

You can look at the source of each of those extensions to see what exactly they're doing.

通常,他们会设置配置,在请求事件之前和之后设置回调,并通常使用应用程序中的信息进行初始化.

In general, they are setting up configuration, setting up callbacks for before and after request events, and generally using information from the app to initialize.

如果您不通过应用程序(或稍后调用 init_app ),则扩展名将无法完成初始化并且可能无法使用.

If you don't pass the app (or later call init_app), then the extension can't finish initializing and could be unusable.

这篇关于用Flask中的flask实例初始化扩展的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:10