用Flask CLI替换Flask-Script
Jun 7, 2019
打算用Flask CLI
替换掉项目中的Flask-Script
,于是去读Flask CLI
的文档。
基本使用
For the flask script to work, an application needs to be discovered. This is achieved by exporting the FLASK_APP environment variable. It can be either set to an import path or to a filename of a Python module that contains a Flask application.
In that imported file the name of the app needs to be called app or optionally be specified after a colon. For instance mymodule:application would tell it to use the application object in the mymodule.py file.
使用Flask CLI
,首先需要通过声明环境变量FLASK_APP
来导入一个Flask application
。FLASK_APP
可以指向import path
中的Flask application
,也可以指向一个内含了Flask application
的模块。