__init__.py
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import Flask
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from config import Config
import logging
from logging.handlers import RotatingFileHandler,TimedRotatingFileHandler
def setup_log():
# 设置日志的记录等级
logging.basicConfig(level=Config.LOG_LEVEL) # 调试debug级
# 创建日志记录器,指明日志保存的路径、每个日志文件的最大大小、保存的日志文件个数上限
file_log_handler = RotatingFileHandler(Config.LOG_FOLDER, maxBytes=1024 * 1024 * 100, backupCount=10)
# 创建日志记录的格式 日志等级 输入日志信息的文件名 行数 日志信息
log_file_handler = TimedRotatingFileHandler(filename=Config.LOG_FOLDER, when="D", interval=1, backupCount=15)
formatter = logging.Formatter('%(asctime)s : %(message)s')
# 为刚创建的日志记录器设置日志记录格式
file_log_handler.setFormatter(formatter)
# 为全局的日志工具对象(flask app使用的)添加日志记录器
logging.getLogger().addHandler(file_log_handler)
# Flask-SQLAlchemy plugin
db = SQLAlchemy()
# # Flask-Migrate plugin
migrate = Migrate()
def create_app(config_class=Config):
setup_log()
app = Flask(__name__,
template_folder="./neotel",
static_folder="./neotel",
static_url_path="")
app.config.from_object(config_class)
# Enable CORS
CORS(app, supports_credentials=True)
# Init Flask-SQLAlchemy
db.init_app(app)
# Init Flask-Migrate
migrate.init_app(app, db)
# 注册 blueprint
from app.api import bp as api_bp
app.register_blueprint(api_bp, url_prefix='/api')
return app
from app import models,utils,saved_model