def create_app(config_name, config_path=None): app = Flask(__name__) # 读取配置文件 if not config_path: pwd = os.getcwd() config_path = os.path.join(pwd, 'config/config.yaml') if not config_name: config_name = 'PRODUCTION' # 读取配置文件 conf = read_yaml(config_name, config_path) app.config.update(conf) # 更新Celery配置信息 celery_conf = "redis://{}:{}/{}".format(app.config['REDIS_HOST'], app.config['REDIS_PORT'], app.config['REDIS_DB']) celery_app.conf.update({ "broker_url": celery_conf, "result_backend": celery_conf }) # 注册接口 # register_api(app=app, routers=router) app.register_blueprint(api_bp, url_prefix='/api') # 返回json格式转换 app.json_encoder = JSONEncoder # 注册数据库连接 db.app = app db.init_app(app) migrate.init_app(app, db) # 注册邮件功能 mail.init_app(app) # 启动定时任务 if app.config.get("SCHEDULER_OPEN"): scheduler_init(app) # 日志文件目录 if not os.path.exists(app.config['LOGGING_PATH']): os.mkdir(app.config['LOGGING_PATH']) # 报表文件目录 if not os.path.exists(app.config['REPORT_PATH']): os.mkdir(app.config['REPORT_PATH']) # 日志设置 with open(app.config['LOGGING_CONFIG_PATH'], 'r', encoding='utf-8') as f: dict_conf = yaml.safe_load(f.read()) logging.config.dictConfig(dict_conf) # 读取msg配置 with open(app.config['RESPONSE_MESSAGE'], 'r', encoding='utf-8') as f: msg = yaml.safe_load(f.read()) app.config.update(msg) return app
def create_app(config_name, config_path=None): app = Flask(__name__) # 处理跨域 CORS(app, resources=r'/*') # 读取配置文件 if not config_path: pwd = os.getcwd() config_path = os.path.join(pwd, 'config/config.yaml') if not config_name: config_name = 'PRODUCTION' # 读取配置文件 conf = read_yaml(config_name, config_path) app.config.update(conf) # 更新邮箱发送配置 EmailSender.set_address(app.config.get("SEND_EMAIL").get('ADDRESS')) EmailSender.set_authcode(app.config.get("SEND_EMAIL").get('AUTHCODE')) EmailSender.set_stmphost(app.config.get("SEND_EMAIL").get('HOST')) EmailSender.set_stmpport(app.config.get("SEND_EMAIL").get('PORT')) # 注册接口 register_api(app=app, routers=router) # 返回json格式转换 app.json_encoder = JSONEncoder # 注册数据库连接 db.app = app db.init_app(app) # 启动定时任务 if app.config.get("SCHEDULER_OPEN"): scheduler_init(app) # 日志文件目录 if not os.path.exists(app.config['LOGGING_PATH']): os.mkdir(app.config['LOGGING_PATH']) # 报表文件目录 if not os.path.exists(app.config['REPORT_PATH']): os.mkdir(app.config['REPORT_PATH']) # 日志设置 with open(app.config['LOGGING_CONFIG_PATH'], 'r', encoding='utf-8') as f: dict_conf = yaml.safe_load(f.read()) logging.config.dictConfig(dict_conf) # 读取msg配置 with open(app.config['RESPONSE_MESSAGE'], 'r', encoding='utf-8') as f: msg = yaml.safe_load(f.read()) app.config.update(msg) return app
def create_app(config_name, config_path=None): app = Flask(__name__) # 读取配置文件 if not config_path: pwd = os.getcwd() config_path = os.path.join(pwd, 'config/config.yaml') if not config_name: config_name = 'PRODUCTION' # 读取配置文件 conf = read_yaml(config_name, config_path) app.config.update(conf) # 注册接口 register_api(app=app, routers=router) # 返回json格式转换 app.json_encoder = JSONEncoder # 注册数据库连接 db.app = app db.init_app(app) # 启动定时任务 if app.config.get("SCHEDULER_OPEN"): scheduler_init(app) # 日志文件目录 if not os.path.exists(app.config['LOGGING_PATH']): os.mkdir(app.config['LOGGING_PATH']) # 报表文件目录 if not os.path.exists(app.config['REPORT_PATH']): os.mkdir(app.config['REPORT_PATH']) # 日志设置 with open(app.config['LOGGING_CONFIG_PATH'], 'r', encoding='utf-8') as f: dict_conf = yaml.safe_load(f.read()) logging.config.dictConfig(dict_conf) # 读取msg配置 with open(app.config['RESPONSE_MESSAGE'], 'r', encoding='utf-8') as f: msg = yaml.safe_load(f.read()) app.config.update(msg) return app
def create_app(config_name, config_path=None): app = Flask(__name__) # 读取配置文件 if not config_path: pwd = os.getcwd() config_path = os.path.join(pwd, 'config/config.yaml') if not config_name: config_name = 'PRODUCTION' # 读取配置文件 conf = read_yaml(config_name, config_path) app.config.update(conf) app.config['ELASTIC_APM'] = { 'SERVICE_NAME': 'ET_prod', 'SECRET_TOKEN': '', 'SERVER_URL': 'http://47.113.91.65:8200', } # 更新Celery配置信息 celery_conf = "redis://{}:{}/{}".format(app.config['REDIS_HOST'], app.config['REDIS_PORT'], app.config['REDIS_DB']) celery_conf_prod = "redis://:{}@{}:{}/{}".format( app.config['REDIS_PWD_PROD'], app.config['REDIS_HOST_PROD'], app.config['REDIS_PORT'], app.config['REDIS_DB']) celery_app.conf.update({ "broker": celery_conf_prod, "broker_url": celery_conf_prod, "result_backend": celery_conf_prod }) # 注册接口 register_api(app=app, routers=router) # 返回json格式转换 app.json_encoder = JSONEncoder # 注册数据库连接 db.app = app db.init_app(app) # 启动定时任务 if app.config.get("SCHEDULER_OPEN"): scheduler_init(app) # 日志文件目录 if not os.path.exists(app.config['LOGGING_PATH']): os.mkdir(app.config['LOGGING_PATH']) # 报表文件目录 if not os.path.exists(app.config['REPORT_PATH']): pass # os.mkdir(app.config['REPORT_PATH']) # 日志设置 with open(app.config['LOGGING_CONFIG_PATH'], 'r', encoding='utf-8') as f: dict_conf = yaml.safe_load(f.read()) logging.config.dictConfig(dict_conf) # 读取msg配置 with open(app.config['RESPONSE_MESSAGE'], 'r', encoding='utf-8') as f: msg = yaml.safe_load(f.read()) app.config.update(msg) CORS(app) apm = ElasticAPM(app) return app