53 lines
1.1 KiB
Python
53 lines
1.1 KiB
Python
|
# 项目初始化文件
|
||
|
import logging
|
||
|
from logging.handlers import RotatingFileHandler
|
||
|
from flask import Flask
|
||
|
from redis import StrictRedis
|
||
|
from flask_wtf.csrf import CSRFProtect
|
||
|
from flask_session import Session
|
||
|
from flask_sqlalchemy import SQLAlchemy
|
||
|
|
||
|
from application.settings.dev import DevelopmentConfig
|
||
|
from application.settings.prop import ProductionConfig
|
||
|
from common.config.factory import create_app
|
||
|
|
||
|
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
|