def create_app(): app = Flask('rmon') #根据不同的环境变量(RMON_ENV)值 选择开发环境 env = os.environ.get('RMON_ENV') if env in ('pro', 'prod', 'product'): app.config.from_object(ProductConfig) else: app.config.from_object(DevConfig) app.config.from_envvar('RMON_SETTINGS', silent=True) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #在Flask 类中注册 蓝图 app.register_blueprint(api) #使用了flask_sqlalchemy 扩展,db.init_app(app)会自动在配置文件中查找 #SQLALCHEMY_DATABASE_URI 配置项 配置数据库地址。 db.init_app(app) #开发环境中,自动在 内存数据库中创建数据库。 if app.debug: with app.app_context(): db.create_all() return app
def create_app(): """ create an initiaze flask app """ app = Flask("rmon") env = os.environ.get('RMON_ENV') if env in ('pro', 'prod', 'product'): app.config.from_object(ProductConfig) else: app.config.from_object(DevConfig) app.config.from_envvar('RMON_SETTINGS', silent=True) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.register_blueprint(api) db.init_app(app) if app.debug: with app.app_context(): db.create_all() return app
def init_db(): """ """ print("sqlite database file is %s" % app.config['SQLALCHEMY_DATABASE_URI']) db.create_all()
def db(app): """数据库 """ with app.app_context(): database.create_all() yield database database.drop_all()
def init_db(): """ initialize database """ print("sqlite3 database file is {}".format( app.config['SQLALCHEMY_DATABASE_URI'])) db.create_all()
def create_app(): """ create and initialize Flask app """ app = Flask("rmon") env = os.environ.get('RMON_ENV') if env in ('pro', 'prod', 'product'): app.config.from_object(ProductConfig) else: app.config.from_object(DevConfig) # get settings from env app.config.from_envvar("RMON_SETTINGS", silent=True) app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False # register the blueprint app.register_blueprint(api) # initialize db db.init_app(app) if app.debug: with app.app_context(): db.create_all() return app
def create_app(): """ 创建并初始化 Flask app Args: config (dict): 配置字典 Returns: app (object): Flask App 实例 """ app = Flask('rmon') # 根据环境变量加载开发环境或生产环境配置 env = os.environ.get('RMON_ENV') if env in ('pro', 'prod', 'product'): app.config.from_object(ProductConfig) else: app.config.from_object(DevConfig) # 从环境变量 RMON_SETTINGS 指定的文件中加载配置 app.config.from_envvar('RMON_SETTINGS', silent=True) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False # 注册 Blueprint app.register_blueprint(api) # 初始化数据库 db.init_app(app) # 如果是开发环境则创建所有数据库表 if app.debug: with app.app_context(): db.create_all() return app
def db(app): """数据库 """ with app.app_context(): database.create_all() print("uuu") yield db database.drop_all()
def create_app(config): app = Flask("rmon") app.config.from_object(configs.get(config, "development")) # 从环境变量 RMON_SETTINGS 指定的文件中加载配置 app.config.from_envvar('RMON_SETTINGS', silent=True) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False get_config_from_file(app) register_extensions(app) register_blueprints(app) # 如果是开发环境则创建所有数据库表 if app.debug and not app.testing: with app.app_context(): db.create_all() name, password = User.create_administrator() app.logger.debug('create administrator name/password %s/%s', name, password) return app return app
def create_app(): app = Flask('rmon') env = os.environ.get('RMON_ENV') if env in ('pro', 'prod', 'production'): app.config.from_object(ProductionConfig) else: app.config.from_object(DevConfig) app.config.from_envvar('RMON_SETINGS', silent=True) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.register_blueprint(api) db.init_app(app) if app.debug: db.create_all() return app
def create_app(): app = Flask('rmon') env = os.environ.get('RMON_ENV') if env in ('pro', 'prod', 'product'): app.config.from_object(ProductConfig) else: app.config.from_object(DevConfig) app.config.from_envvar('RMON_SETTINGS', silent=True) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False #注册Blueprint app.register_blueprint(api) #初始化数据库 db.init_app(app) #如果是开发环境则创建所有数据库表 if app.debug: with app.app_context(): db.create_all() return app
def init_db(): ''' 初始化数据库 ''' print('sqlite3 database file is %s'% app.config['SQLALCHEMY_DATABASE_URI']) db.create_all()
def db(app): with app.app_context(): database.create_all() yield db database.drop_all()
def init_db(): """ initialize database """ print("sqlite3 database file is %s" % app.config["SQLALCHEMY_DATABASE_URI"]) db.create_all()
def init_db(): ''' initial database ''' print("sqlite3 database file is %s" % app.config['SQLALCHEMY_DATABASE_URI']) db.create_all()
def init_db(): print('sqlite3 database file is {}'.format( app.config['SQLALCHEMY_DATABASE_URI'])) db.create_all()
def init_db(): print('sqlite3 database file is %s' % app.congif['SQLALCHEMY_DATABASE_URI']) db.create_all()