コード例 #1
0
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 = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)
    app.register_blueprint(blueprint=user_blueprint, url_prefix='/user')

    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[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:123456@localhost:3306/db_flask_user'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    sess = Session()
    sess.init_app(app=app)
    db.init_app(app=app)
    return app
コード例 #2
0
ファイル: functions.py プロジェクト: zhuyinyin/flask
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 = Flask(__name__,
                static_folder=static_dir,
                template_folder=templates_dir)
    # 注册用户登录蓝图
    app.register_blueprint(blueprint=userlogin_bpt, url_prefix='/')

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+mysqlconnector://root:[email protected]:3306/flaskdemo2'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # 设置session密钥
    app.config['SECRET_KEY'] = 'secret_key'

    db.init_app(app=app)

    with app.app_context():
        db.create_all()

    return app
コード例 #3
0
def create_app():
    # 写法一  目的获取模板和静态资源路径
    # app = Flask(__name__,
    #             static_folder='../static',
    #             template_folder='../tempaltes')

    # 写法二
    app = Flask(
        __name__,
        static_folder=static_dir,
        template_folder=template_dir,
    )
    # 注册蓝图
    app.register_blueprint(user_blueprint, url_prefix='/my_user')
    app.register_blueprint(house_blueprint, url_prefix='/house')
    app.register_blueprint(order_blueprint, url_prefix='/order')

    # 设置数据库
    app.config['SQLALCHEMY_DATABASE_URI'] = get_sqlalchemy_uri(MYSQL_DATABASE)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    app.config['SESSION_TYPE'] = 'redis'
    app.config['SESSION_REDIS'] = redis.Redis(host=REDIS_DATABASE['HOST'],
                                              port=REDIS_DATABASE['PORT'])

    app.config['SECRET_KEY'] = '123456'
    app.debug = True

    # bar = DebugToolbarExtension()
    se = Session()

    # bar.init_app(app)
    se.init_app(app)
    db.init_app(app)

    return app
コード例 #4
0
ファイル: ext_init.py プロジェクト: ThreerEyed/flask_1
def ext_init(app):

    se = Session()
    se.init_app(app=app)
    db.init_app(app=app)
    api.init_app(app)
コード例 #5
0
# -*- coding: utf-8 -*-
# @Time    : 2018/10/10 9:24
# @Author  : G.Hope
# @Email   : [email protected]
# @File    : manager.py
# @Software: PyCharm

from flask import Flask
from flask_script import Manager

from user.models import db
from user.views import blue

app = Flask(__name__)

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

app.config[
    'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:[email protected]:3306/flask'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 初始化app和db
db.init_app(app)

manager = Manager(app=app)

if __name__ == '__main__':
    manager.run()
コード例 #6
0
def init_ext(app):
    # 绑定app和db
    db.init_app(app)