Flask-Script
程序员文章站
2023-09-28 18:43:28
安装pipinstallFlask-Script-ihttps://pypi.douban.com/simple Flsak加入flask-script #-*-coding:utf-8-*- importapps fromappsimportdb fromflask_scriptimportMan... ......
安装pip install flask-script -i https://pypi.douban.com/simple
flsak加入flask-script
- # -*- 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 漂亮