#!flask/bin/python import os from flask_script import Manager from logging.handlers import RotatingFileHandler from app import create_app import logging app = create_app() app_manager = Manager(app) if __name__ == '__main__': if not app.debug: if not os.path.exists('logs'): os.mkdir('logs') logger = logging.getLogger('app') file_handler = RotatingFileHandler('logs/microblog.log', maxBytes=10240, backupCount=10) file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s: %(message)s [in %(pathname)s:%(lineno)d]')) logger.setLevel(logging.INFO) file_handler.setLevel(logging.INFO) logger.addHandler(file_handler) logger.info('App startup') app_manager.debug = True app_manager.run()
# # 配置数据库的迁移操作 # 导入app工程 from app import app # 导入数据库 from db_operate import db # 导入Manager用来设置应用程序可通过指令操作 from flask_script import Manager #导入数据库迁移类和数据库迁移指令类 from flask_migrate import Migrate, MigrateCommand # 构建指令,设置当前app受指令控制(即将指令绑定给指定app对象) manage = Manager(app) # 构建数据库迁移操作,将数据库迁移指令绑定给指定的app和数据库 migrate = Migrate(app, db) # 添加数据库迁移指令,该操作保证数据库的迁移可以使用指令操作 manage.add_command('db', MigrateCommand) #以下为当指令操作runserver时,开启服务。 if __name__ == '__main__': manage.debug = True manage.run("0.0.0.0", 5000)