コード例 #1
0
def create_app(config_object=configs.ProdConfig):
    app = connexion.App(__name__)
    app.add_api("openapi.yml",
                resolver=RestyResolver("api"),
                strict_validation=True)
    app.app.config.from_object(config_object)
    db.init_app(app.app)
    app.app.app_context().push()
    db.create_all()
    return app
コード例 #2
0
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile("config.py")
    marshmallow.init_app(app)
    db.init_app(app)
    with app.app_context():
        db.create_all()
    initialize_error_handler(app)
    initialize_blueprints(app)
    return app
コード例 #3
0
ファイル: web.py プロジェクト: wang9546/Flask_SQLAlchemy
def create_app():
    app = Flask(__name__)
    # 初始化App配置专门针对 SQLAlchemy 进行配置
    # SQLALCHEMY_DATABASE_URI 配置 SQLAlchemy 的链接字符串儿
    app.config[
        "SQLALCHEMY_DATABASE_URI"] = 'mysql+pymysql://root:@127.0.0.1:3306/homework?charset=utf8'
    # SQLALCHEMY_POOL_SIZE 配置 SQLAlchemy 的连接池大小
    app.config["SQLALCHEMY_POOL_SIZE"] = 5
    # SQLALCHEMY_POOL_TIMEOUT 配置 SQLAlchemy 的连接超时时间
    app.config["SQLALCHEMY_POOL_TIMEOUT"] = 15
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    # 初始化SQLAlchemy , 本质就是将以上的配置读取出来
    db.init_app(app)
    app.register_blueprint(user)
    return app
コード例 #4
0
import unittest

from flask import Flask
from flask_bcrypt import Bcrypt

import cover
import log_config
from orm import db
from terms.endpoints import terms_bp

logger_debug = logging.getLogger('debug')
app = Flask(__name__)
configuration = os.getenv('CONFIGURATION', 'development')
config_dir = os.path.abspath(os.path.dirname(__file__))
app.config.from_pyfile('configuration/{}.py'.format(configuration))
db.init_app(app)
bcrypt = Bcrypt(app)
app.register_blueprint(terms_bp)


@app.cli.command(with_appcontext=False)
def test():
    """Runs the unit tests without test coverage."""
    tests = unittest.TestLoader().discover('tests', pattern='test*.py')
    result = unittest.TextTestRunner(verbosity=2).run(tests)
    if result.wasSuccessful():
        return 0
    return 1


@app.cli.command(with_appcontext=False)