标签:name server 数据 int div main com 完成 style
flask-scripts通过命令行操作flask。
1. 安装
pip install flask-script
2. 使用
1 from flask_script import Manager 2 from valuegood import app 3 4 manager = Manager(app) 5 @manager.command 6 def runserver(): 7 print(‘服务器跑起来了‘) 8 9 if __name__ == ‘__main__‘: 10 manager.run()
在cmd中运行:python manager.py runserver
3 操作数据库
1 from flask_script import Manager 2 3 DNManager = Manager() 4 5 @DNManager.command 6 def init(): 7 print(‘数据库初始化完成‘)
1 from flask_script import Manager 2 from valuegood import app 3 from db import DNManager 4 5 manager = Manager(app) 6 7 @manager.command 8 def runserver(): 9 print(‘服务器跑起来了‘) 10 11 manager.add_command(‘db‘, DNManager) 12 13 if __name__ == ‘__main__‘: 14 manager.run()
在cmd中运行:python manager.py db init
标签:name server 数据 int div main com 完成 style
原文地址:https://www.cnblogs.com/clairexxx/p/9743526.html