コード例 #1
0
ファイル: app.py プロジェクト: zhulinyi422/huxiuwang_blog
def create_app():
    static_dir = os.path.join(BASE_DIR, 'static')
    templates_dir = os.path.join(BASE_DIR, 'templates')
    app = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)
    app.register_blueprint(blueprint=house_blueprint, url_prefix='/blog')
    app.register_blueprint(blueprint=user_blueprint, url_prefix='/user')
    app.register_blueprint(blueprint=info_blueprint, url_prefix='/info')
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:zly1995422@localhost:3306/blog'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['SECRET_KEY'] = 'secret_key'
    app.config['SESSION_TYPE'] = 'redis'
    app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379)
    app.config['SESSION_KEY_PREFIX'] = 'flask'
    db.init_app(app=app)
    Session(app=app)
    return app
コード例 #2
0
ファイル: __init__.py プロジェクト: githubassets/AWDDocker
def create_app(config='APP.config.TestingConfig'):
    app = Flask(__name__)
    with app.app_context():
        app.config.from_object(config)

        from APP.models import db
        db.init_app(app)
        migrate.init_app(app, db)
        init_db()

        app.db = db

        from APP.utils import init_utils
        init_utils(app)

        from APP.users import users
        app.register_blueprint(users)

        return app
コード例 #3
0
ファイル: functions.py プロジェクト: lanms/grocery
def create_app():

    BASE_DIR = os.path.dirname(os.path.dirname(__file__))
    static_dir = os.path.join(BASE_DIR, 'static')
    templates_dir = os.path.join(BASE_DIR, 'templates')

    # 初始化 app
    app = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)
    # 注册蓝图
    app.register_blueprint(blueprint=hello_blueprint, url_prefix='/hello')

    app.register_blueprint(blueprint=user_blueprint, url_prefix='/user')

    # 设置 密钥  数据库  redis
    app.config['SECRET_KEY'] = 'secret_key'
    app.config['SESSION_TYPE'] = 'redis'  # 选择数据库类型, 默认连接本地 redis

    # 连接指定的地址, 连接本地, 设置数据库的 地址, 默认的可以不写
    app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379)
    # 添加 sessionid的前缀
    app.config['SESSION_KEY_PREFIX'] = 'flask'

    # 配置数据库 MySQL
    app.config['SQLALCHEMY_DATABASE_URI'] =\
        'mysql+pymysql://root:123456@localhost:3306/hello_flask'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # 导入 session
    # 第一种方式
    # se = Session()
    # se.init_app(app=app)
    # 第二种方式
    Session(app=app)

    # 初始化数据库
    db.init_app(app=app)  # 第一种写法

    return app
コード例 #4
0
def create_app():

    static_dir = os.path.join(BASE_DIR, 'static')
    templates_dir = os.path.join(BASE_DIR, 'templates')

    app = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)

    app.register_blueprint(blueprint=user_blueprint, url_prefix='/user')
    app.register_blueprint(blueprint=house_blueprint, url_prefix='/house')

    app.config['SQLALCHEMY_DATABASE_URI'] = \
        "mysql+pymysql://root:123456@localhost:3306/jiajuflask"
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    app.config['SECRET_KEY'] = 'secret_key'
    app.config['SESSION_TYPE'] = 'redis'
    app.config['SESSION_REDIS'] = redis.Redis(host='127.0.0.1', port=6379)

    #初始化
    se.init_app(app=app)
    db.init_app(app=app)
    return app