安裝pip install Flask-Script -i https://pypi.douban.com/simple python
Flsak加入flask-script flask
-
# -*- coding: utf-8 -*-
-
import apps
-
from apps import db
-
from flask_script import Manager
-
my_app = apps.create_app()
-
manager = Manager(my_app)
-
-
# ---------------- flask_script
-
# 直接運行命令
-
@manager.command
-
def runflask():
-
my_app.run()
-
return 'ok'
-
-
# 啓動時帶參數
-
# --name 是-n的全稱, dest是參數的命名
-
@manager.option('-n', '--name', dest='arg')
-
@manager.option('-s', '--say', dest='say')
-
def open_flask(arg, say):
-
my_app.run(arg, say)
-
return arg, say
-
-
-
if __name__ == '__main__':
-
# my_app.run('0.0.0.0', port=5000, debug=True)
-
manager.run() # flask_script
-
-
-
運行
-
python manager.py talk -n 趙麗穎 -s 漂亮
-
python manager.py talk --name 趙麗穎--say 漂亮