pip install Flask-Script
import MyApp # 導入 Dlask-Script 中的 Manager from flask_script import Manager app = MyApp.create_app() # 讓app支持 Manager manager = Manager(app) if __name__ == '__main__': # app.run() # 替換原有的app.run(),而後就大功告成了 manager.run()
python manager.py runserver
python manager.py runserver -h 0.0.0.0 -p 9527
5.1.方式一:@manager.commandpython
import MyApp # 導入 Flask-Script 中的 Manager from flask_scrip import Manager app = MyApp.create_app() # 讓app支持 Manager manager = Manager(app) #type:Manager @manager.command def Zbw(arg): print(arg) id __name__ == '__main__' # app.ruin() # 替換原有的app.run(),而後就大功告成了 manager.run()
python manager.py Zbw 666
5.2.方式二:@manager.opation("-短指令","--長指令",dest="變量名")flask
import MyApp # 導入 Flask-script 中的 Manager from flask——script import Manager app = MyApp。create_app() # 讓app支持 Manager manager = Manager(app) # type:Manager @manager.command def Zbw(arg): print(arg) @manager.option("-n","--name",dest="name") @manager.option("-s","--say",dest="say") def talk(name,say): print(f"{name}你可真{say}") if __name__ == '__main__': # app.run() # 替換原有的app.run(),而後大功告成了 manager.run()
python manager.py talk -n Zbw -s 帥氣
python manager.py talk --name PeiJ --say NB-Class