部署流程
manage.py 部署命令 每次安装升级只需运行deploy命令即可完成操作
@manager.command def deploy(): """执行部署任务""" from flask_migrate import upgrade from app.models import Role, User # 把数据库迁移到最新修订版本 upgrade() # 创建用户角色 Role.insert_roles() # 让所有用户都关注此用户 User.add_self_follows()
把生产环境中的错误写入日志
config.py 程序出错时发送电子邮件
class ProductionConfig(Config): SQLALCHEMY_DATABASE_URI = os.environ.get(‘DATABASE_URL‘) or ‘sqlite:///‘ + os.path.join(basedir,‘data.sqlite‘) @classmethod def init_app(cls,app): Config.init_app(app) # 把错误通过电子邮件发送给管理员 import logging from logging.handlers import SMTPHandler credentials = None secure = None if getattr(cls,‘MAIL_USERNAME‘,None) is not None: credentials = (cls.MAIL_USERNAME,cls.MAIL_PASSWORD) if getattr(cls,‘MAIL_USE_TLS‘,None): secure=() mail_handler = SMTPHandler( mailhost=(cls.MAIL_SERVER,cls.MAIL_PORT), fromaddr=cls.FLASKY_MAIL_SENDER, toaddrs=[cls.FLASKY_ADMIN], subject=cls.FLASKY_MAIL_SUBJECT_PREFIX+‘Application Error‘, credentials=credentials, secure=secure ) mail_handler.setLevel(logging.ERROR) app.logger.addHandler(mail_handler)
时间: 2024-10-09 18:52:08