Command to start the flask and custom commands

By the command to start the flask, and the custom command

"""
自定义命令,通过命令启动flask
安装:pip install flask-script
"""

from flask_script import Manager
from flask import Flask
app = Flask(__name__)
manage = Manager(app)


@app.route('/')
def index():
    return 'ok'


# 自定义命令
@manage.command
def cd(arg, t):
    # 命令的名字的和函数名一致,有参数也必须传参数
    print(arg, t)


@manage.option('-n', '--name', dest='name')
@manage.option('-u', '--url', dest='url') # dest的名字必须个你自定义命令中的参数名一致
def cmd(name, url):
    print(name, url)


if __name__ == '__main__':
    manage.run()

Guess you like

Origin www.cnblogs.com/yafeng666/p/12535883.html