码迷,mamicode.com
首页 > 其他好文 > 详细

flask项目配置

时间:2019-07-14 19:40:41      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:except   迁移   npm   creat   开启   tab   ids   base   main   

config.py:

class Config(object):
    """项目的配置"""
    DEBUG = True
    SECRET_KEY = J5RxXy9emBt78iIVP1beu4k4XbbgWxcZI+UrvD7afM9tXNPmnHw8xn4c5+qjnEB1
    # 为Mysql添加配置
    SQLALCHEMY_DATABASE_URI = mysql://root:123456@127.0.0.1:3306/information27
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    # 修改数据模型后自动执行,不需要commit()
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True

    # Redis的配置
    REDIS_HOST = 127.0.0.1
    REIDS_PORT = 6379

    # Session保存配置
    SESSION_TYPE = redis
    # 开启session签名
    SESSION_USE_SIGNER = True
    # 指定Session保存的redis
    SESSION_REDIS = StrictRedis(host=REDIS_HOST, port=REIDS_PORT)
    # 设置需要过期
    SESSION_PERMANENT = False
    # 设置过期时间
    PERMANENT_SESSION_LIFETIME = 86400 * 2
    # 设置日志等级
    LOG_LEVEL = logging.DEBUG

manager.py

app = create_app(development)

manager = Manager(app)
# 将app与db关联
Migrate(app, db)
# 将迁移命令添加到manager中
manager.add_command(db, MigrateCommand)

# 添加管理员
@manager.option(-n, -name, dest=name)
@manager.option(-p, -password, dest=password)
def createsuperuser(name, password):
    if not all([name, password]):
        print(参数不足)

    user = User()
    user.nick_name = name
    user.mobile = name
    user.password = password
    user.is_admin = True

    try:
        db.session.add(user)
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        print(e)

    print(添加成功)
if __name__ == ‘__main__‘:
# print(app.url_map)
manager.run()

 

flask项目配置

标签:except   迁移   npm   creat   开启   tab   ids   base   main   

原文地址:https://www.cnblogs.com/xiangxiaolin/p/11185069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!