# 项目初始化文件 from flask import Flask from flask_session import Session from flask_wtf.csrf import CSRFProtect from application.settings.dev import DevelopmentConfig from application.settings.prop import ProductionConfig config = { 'dev': DevelopmentConfig, 'prop': ProductionConfig, } def init_app(config_name): """ 项目初始化 :param config_name: :return: """ # 主应用的根目录 app = Flask(__name__) # 设置配置类 Config = config[config_name] # 加载配置 app.config.from_object(Config) # redis的连接初始化 # global redis_store # redis_store = StrictRedis(host=Config.CACHE_REDIS_HOST, port=Config.CACHE_REDIS_PORT, db=0) # 开启CSRF防范 CSRFProtect(app) # 开启session Session(app) # 增加数据库连接 # db.init_app(app) # # # 启用日志 # setup_log(Config) return app