Flask web开发之路九
flask_scripts介绍 项目结构如下: flask_script_demo.py文件: from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(debug=True) db_scripts.py文件: from flask_script import Manager DBManager = Manager() @DBManager.command def init(): print('数据库初始化完成') @DBManager.command def migrate(): print('数据库迁移成功') manage.py文件: from flask_script import Manager from flask_script_demo import app from db_scripts import DBManager manager = Manager(app) #和数据库相关的文件,都放在一起 @manager.command def runserver(): print('服务器跑起来了') manager.add_command('db'