def create_app(config=None): app = Flask('tigereye') app.config.from_object(config) app.json_encoder = JSONEncoder configure_views(app) db.init_app(app) return app
def create_app(config=None): # 生成app app = Flask(__name__) # 导入配置文件 app.config.from_object("tigereye.configs.default.DefaultConfig") app.config.from_object(config) # 使用配置的json处理方式 app.json_encoder = JSONEncoder # 注册views configure_views(app) # app的debug模式关闭 if not app.debug: # 邮件配置 mail_handler = SMTPHandler( app.config['EMAIL_HOST'], app.config['SERVER_EMAIL'], # app.config['EMAIL_PORT'], app.config['ADMINS'], 'TIGEREYE ALERT', credentials=( app.config['EMAIL_HOST_USER'], app.config['EMAIL_HOST_PASSWORD'] ) ) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter(Formatter(''' Message Type: %(levelname)s Location: %(pathname)s: %(lineno)d Module: %(module)s Function: %(funcName)s Time: %(asctime)s Message: %(message)s ''')) app.logger.addHandler(mail_handler) # 设置app的logger级别 app.logger.setLevel(logging.INFO) # 指定logger文件名 file_handle=FileHandler(os.path.join(app.config["LOG_DIR"],"app.log")) # 设置logger级别 file_handle.setLevel(logging.INFO) # 设置logger格式 file_handle.setFormatter(Formatter( "%(asctime)s %(levelname)s:%(message)s" )) # app中logger设置添加配置 app.logger.addHandler(file_handle) # 配置数据库 db.init_app(app) app.logger.info("create app succeful") return app
def create_app(config=None): app = Flask('tigereye') app.config.from_object(config) app.json_encoder = JSONEncoder configure_views(app) db.init_app(app) # if not app.debug: # app.logger.setlevel(logiging) return app
def create_app(): app = Flask(__name__) # app.debug = True app.config.from_object('tigereye.configs.default.DefaultConfig') #注册view到app 中 MiscView.register(app) CinemaView.register(app) db.init_app(app) return app
def create_app(config = None): app = Flask(__name__) # app.debug = debug app.config.from_object('tigereye.configs.default.DefalutConfig') app.config.from_object(config) app.json_encoder = JSONEncoder if not app.debug: app.logger.setLevel(logging.INFO) mail_handler = SMTPHandler( app.config['EMAIL_HOST'], app.config['SERVER_EMAIL'], # app.config['EMAIL_PORT'], app.config['ADMINS'], 'TIGEREYE ALERT', credentials = ( app.config['EMAIL_HOST_USER'], app.config['EMAIL_HOST_PASSWORD'] ) ) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter(Formatter(''' Message Type: %(levelname)s Location: %(pathname)s: %(lineno)d Module: %(module)s Function: %(funcName)s Time: %(asctime)s Message: %(message)s ''')) app.logger.addHandler(mail_handler) file_handler = FileHandler(os.path.join(app.config['LOG_DIR'],'app.log')) file_handler.setLevel(logging.INFO) file_handler.setFormatter(Formatter( '%(asctime)s %(levelname)s : %(message)s' )) app.logger.addHandler(file_handler) db.init_app(app) configure_views(app) app.logger.info('create_app_text') return app
def create_app(config = None): '''创建一个flask app对象并返回''' app = Flask(__name__) # app.debug = True #读取配置文件 app.config.from_object('tigereye.configs.default.DefaultConfig') #注册view到app 中 app.config.from_object(config) app.json_encoder = JsonEncode configer_views(app) #初始化sqlalchemy配置 db.init_app(app) #配置日志 if not app.debug: app.logger.setLevel(logging.INFO) mail_handler = SMTPHandler( app.config['EMAIL_HOST'], app.config['SERVER_EMAIL'], app.config['ADMINS'], 'TIGEREYE ALERT', credentials=(app.config['EMAIL_HOST_USER'], app.config['EMAIL_HOST_PASSWORD']) ) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter(logging.Formatter(''' Message type: %(levelname)s Location: %(pathname)s: %(lineno)d Module: %(module)s Function: %(funcName)s Time: %(asctime)s Message: %(message)s ''')) app.logger.addHandler(mail_handler) file_handler = FileHandler(os.path.join(app.config['LOG_DIR'],'app.log')) file_handler.setLevel(logging.INFO) file_handler.setFormatter(logging.Formatter( '%(asctime)s %(levelname)s : %(message)s' )) app.logger.addHandler(file_handler) app.logger.info('app created.BASE_DIR=%s' % app.config['BASE_DIR']) return app
def create_app(config=None): app = Flask(__name__) # app.debug = debug # 我们平时用的app.config.from_object(config[你自己定义的config字典key名字])才能运行!!! # 另外,记住,config([你自己定义的config字典]),他为什么可以找到,是因为,在程序头上,我们已经定义了from config import config!!! app.config.from_object('tigereye.configs.default.DefalutConfig') app.config.from_object(config) # 替换掉json 的encoder方法 app.json_encoder = JSONEncoder # 只有不是在debug的情况下启用 if not app.debug: app.logger.setLevel(logging.INFO) mail_handler = SMTPHandler( app.config['EMAIL_HOST'], app.config['SERVER_EMAIL'], app.config['ADMINS'], 'TIGEREYE ALERT', credentials=(app.config['EMAIL_HOST_USER'], app.config['EMAIL_HOST_PASSWORD'])) mail_handler.setLevel(logging.ERROR) mail_handler.setFormatter( Formatter(""" Message Type: %(levelname)s Location: %(pathname)s: %(lineno)d Module: %(module)s Function: %(funcName)s Time: %(asctime)s Message: %(message)s """)) app.logger.addHandler(mail_handler) file_handler = FileHandler( os.path.join(app.config['LOG_DIR'], 'app.log')) file_handler.setLevel(logging.INFO) # 定义handler的输出格式 file_handler.setFormatter( Formatter('%(asctime)s %(levelname)s : %(message)s')) app.logger.addHandler(file_handler) # 初始化数据库 db.init_app(app) # 自定义的方法,注册了所有的view configure_view(app) app.logger.info('creat app succ ') return app