昨天在Flask 初始化數(shù)據(jù)的時(shí)候,想使用命令的Flask命令添加自己想要的命令進(jìn)行初始化數(shù)據(jù)庫(kù)操作,卻怎么都無(wú)法在flask命令添加自己的自定義命令,網(wǎng)上搜索的很多辦法,最后自己看了N多文章才找到方法,下面總結(jié)一下:
1、編寫(xiě)自己的啟動(dòng)flask app的 .py文件
2、運(yùn)行,啟動(dòng)flask app
3、把自己的flask app加入到環(huán)境變量中
export FLASK_APP=你自己?jiǎn)?dòng)flask app 的py文件的絕對(duì)路徑
4、命令行執(zhí)行
flask --help
Usage: flask [OPTIONS] COMMAND [ARGS]...
A general utility script for Flask applications.
Provides commands from Flask, extensions, and the application. Loads the
application defined in the FLASK_APP environment variable, or from a
wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
will enable debug mode.
$ export FLASK_APP=hello.py
$ export FLASK_ENV=development
$ flask run
Options:
--version Show the flask version
--help Show this message and exit.
Commands:
init Initialize Albumy.
initdb Initialize the database.
routes Show the routes for the app.
run Runs a development server.
shell Runs a shell in the app context.
就會(huì)發(fā)現(xiàn) Commands 出現(xiàn)了自己添加的自定義命令