# -*- coding:utf-8 -*- from flask_script import Manager # 用于添加终端命令 from flask_migrate import Migrate, MigrateCommand # 用于数据库迁移 from ihome import create_app app, db = create_app('develop') # 通过拆包获取函数返回值 manager = Manager(app) # 创建manager对象 Migrate(app, db) manager.add_command('db', MigrateCommand) # 添加迁移命令 if __name__ == '__main__': manager.run()
from flask import session from flask_script import Manager from flask_migrate import MigrateCommand from ihome import create_app # 创建应用 app = create_app("dev") # 创建管理器 mgr = Manager(app) # 管理器生成迁移命令 mgr.add_command("mc", MigrateCommand) if __name__ == '__main__': mgr.run()
from flask_script import Manager from flask_migrate import Migrate,MigrateCommand import pymysql pymysql.install_as_MySQLdb() from ihome import create_app,db app = create_app('deve') manager = Manager(app) Migrate(app,db) manager.add_command('db',MigrateCommand) if __name__ == '__main__': # print (app.url_map) manager.run()
# -*- coding:utf8 -*- from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import create_app app, db = create_app('develop') manager = Manager(app) migrate = Migrate(app, db) # 数据迁移命令 manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
from ihome import create_app, db # 导入flask脚本 from flask_script import Manager # Migrate迁移的执行者, MigarteCommand命令解析人员 from flask_migrate import Migrate, MigrateCommand # 创建flask的应用对象 app = create_app('product') manager = Manager(app) # 将迁移者保存到app中,再次用到的时候还会用到数据库 Migrate(app, db) # 添加命令 manager.add_command("db", MigrateCommand) if __name__ == '__main__': manager.run()
# coding=utf-8 # Time : 2019/1/7 # Author : achjiang # 从ihome中的init中导入工厂模式创建app from ihome import create_app, db # 导入创建脚本的工具 from flask_script import Manager # 导入数据库迁移工具 from flask_migrate import Migrate, MigrateCommand # 创建app实例 app = create_app("develop") # 创建管理对象 manager = Manager(app) # 迁移数据库 # 将数据库添加都Migrate对象 Migrate(app, db) # 设置指令,db==MigrateCommand manager.add_command("db", MigrateCommand) # 建立models.py文件后: # 1.使用`python2 manage.py db init`命令初始化, # 2.使用`python2 manage.py db migrate -m 'init tables'`命令初始化表 # 3.使用'python manage.py db upgrade'命令升级 if __name__ == "__main__": # 主程序 # app.run()
# coding=utf8 from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import create_app, db app = create_app('develop') # 创建脚本管理器 manager = Manager(app) # 让迁移时,app和数据库建立关联 Migrate(app, db) # 增加db脚本命令 manager.add_command("db", MigrateCommand) if __name__ == '__main__': # app.run() manager.run()
# coding=utf-8 from flask_migrate import Migrate, MigrateCommand from flask_script import Manager from ihome import create_app, db # 需求,不修改业务逻辑的代码,,只通过修改manager文件 # 中的一句代码获取不同配置环境中的app app = create_app('production') # 创建Manage管理对象 ---脚本方式管理对象 manager = Manager(app) Migrate(app, db) # 添加迁移命令 manager.add_command('db', MigrateCommand) @app.route('/', methods=['GET', 'POST']) def index(): # session["name"]= 'itheima' return 'index' if __name__ == '__main__': # 运行开发web服务器 # app.run() manager.run()
#!/usr/bin/python # -*- coding:utf-8 -*- from flask_migrate import Migrate, MigrateCommand from flask_script import Manager from config import DevelopmentConfig from ihome import create_app # 必须导入数据库模型 from ihome.models import User, Area, House, Facility, HouseImage, Order # 由manager.py文件来管理程序的启动,通过对象来加载配置信息 app, db = create_app(DevelopmentConfig) # 托管app的启动 manager = Manager(app) # 执行迁移文件 Migrate(app, db) # 在终端执行迁移需要添加db命令 manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
#coding:utf-8 from ihome import create_app, db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand app = create_app("develop") #传参("develop" "product") #让Python支持命令行工作 manager = Manager(app) #使用migrate 绑定app和db migrate = Migrate(app, db) #添加迁移脚本的命令到manager中 manager.add_command('db', MigrateCommand) #启动项目 if __name__ == "__main__": manager.run()
#!/usr/bin/env python # -*- coding:utf-8 -*- #项目启动文件 from ihome import create_app, db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import models app = create_app("development") Migrate(app, db) manager = Manager(app) manager.add_command("db", MigrateCommand) if __name__ == '__main__': print app.url_map manager.run()
from ihome import create_app,db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand # 创建 app = create_app('produce') manager = Manager(app) migrate = Migrate(app, db) manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
# coding:utf-8 import datetime, string from ihome import create_app, db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand # 创建flask应用对象 app = create_app('dev') manager = Manager(app) Migrate(app, db) manager.add_command('db', MigrateCommand) if __name__ == "__main__": # app.run(host='0.0.0.0',port=7788) # print(app.url_map) today = datetime.datetime.now() print('0.0.0.0 -p 7788', today) manager.run() # python manage.py runserver -h '0.0.0.0' -p 7788 # python manage.py db init # python manage.py db migrate -m 'init' # python manage.py db upgrade
from flask import session from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import create_app, db, models app = create_app('def') # 实例化manager管理对象 manager = Manager(app) # 使用迁移框架 Migrate(app, db) # 添加迁移命令, db就是字符串可以随意指定, MigrateCommand里面有迁移指令 manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
# -*- coding:utf-8 -*- from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import create_app, db, models app = create_app('development') manager = Manager(app) Migrate(app, db) manager.add_command('db', MigrateCommand) if __name__ == '__main__': print(app.url_map) manager.run()
# coding:utf-8 from ihome import create_app, db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand if __name__ == '__main__': app = create_app("develop") # 创建Flask应用对象 Migrate(app, db) # 数据库迁移 manager = Manager(app) # flask-script扩展脚本 manager.add_command('db', MigrateCommand) # 添加迁移命令 manager.run() # 以扩展脚本形式运行
# coding:utf-8 # 该文件只保留启动文件 from ihome import create_app, db # flask应用模式 from flask_script import Manager # 脚本管理 from flask_migrate import Migrate, MigrateCommand # 数据库迁移管理 # 创建flask的应用对象 app = create_app("product") # 管理flask项目 manager = Manager(app) # 数据库迁移脚本 Migrate(app, db) # 管理数据库 manager.add_command("db", MigrateCommand) if __name__ == '__main__': manager.run()
# coding:utf-8 from flask import Flask, render_template from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import create_app, db app = create_app("DevelopmentConfig") # 创建管理工具对象 manager = Manager(app) Migrate(app, db) manager.add_command("app", MigrateCommand) if __name__ == "__main__": manager.run()
# coding:utf-8 from flask_script import Manager from flask_migrate import MigrateCommand, Migrate from ihome import create_app #实际上,程序的运行时需要去区分开发模式和发布模式的,这个模式的控制,也应该由manage来管理 app, db = create_app('develop') manager = Manager(app) #创建迁移对象 migrate = Migrate(app, db) #给manager添加db命令 manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
# # 工厂模式 # def create_app(config_name): # """说明文档 # 创建flask的应用对象(说明信息) # :param config_name: str类型 配置模式的名字 ("develop", "product") - 可选参数 # :return: # """ # app = Flask(__name__) # # # 根据配置模式的民资获取配置参数的类 # config_class = config_map.get(config_name) # app.config.from_object(config_class) # # return app app = create_app("develop") # 创建flask的应用对象 # app = create_app("product") manager = Manager(app) # 创建manager对象 # 把Migrate迁移者创建出来的对象保存到app当中 Migrate(app, db) manager.add_command("db", MigrateCommand) # 添加命令 # # 数据库 # db = SQLAlchemy(app) # 创建数据库,导入APP # # # 创建redis工具(连接对象) # redis_store = redis.StrictRedis(host=Config.REDIS_HOST, port=Config.REDIS_PORT) # # 建立redis的连接东西(redis和程序之间是一种网络通讯,与mysql数据库很象,所以在构建连接对象时要传参数;host主机<app.config.get>:在哪台机器上、port端口号:默认为6379) # # # 利用flask-session,将session数据保存到redis中
# coding=utf-8 from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from ihome import create_app, db, models # 需求:不修改业务逻辑的代码,只通过修改manage.py文件中的一句代码获取不同配置环境中的app app = create_app("development") # 创建Manager管理对象 manager = Manager(app) Migrate(app, db) # 添加迁移命令 manager.add_command("db", MigrateCommand) if __name__ == '__main__': # 运行开发web服务器 # app.run() print app.url_map manager.run()
from ihome import create_app, db from flask_script import Manager from flask_migrate import Migrate, MigrateCommand # 创建flask的应用对象 app = create_app("develop") # 因为创建的app运行在开发模式配置DEBUG=True,所以日志级别会被覆盖,需调product manager = Manager(app) Migrate(app, db) manager.add_command("db", MigrateCommand) if __name__ == '__main__': manager.run()