Ejemplo n.º 1
0
def create_app():
    app = Flask(__name__)
    app.url_map.strict_slashes = False
    api = Api(app)
    Migrate(app, db)

    app.config.from_object(BaseConfig)
    db.init_app(app)

    for url in URLS:
        api.add_resource(*url[0], endpoint=url[1])

    return app
Ejemplo n.º 2
0
def create_app():
    app = Flask(__name__,static_folder='../static')
    app.config.from_object('api.config.setting')
    app.config.from_object('api.config.secure')
    register_blueprints(app)
    db.init_app(app)
    login_manager.init_app(app)

    register_shell_context(app)
    register_commands(app)

    #向jinjia注册自定义函数
    env = app.jinja_env
    env.filters['int_to_datetime'] = int_to_datetime

    return app
Ejemplo n.º 3
0
def create_app():
    """
    The flask application factory.
    """
    app = Flask(__name__)

    CORS(app)  # add CORS

    # check environment variables to see which config to load
    env = os.environ.get("FLASK_ENV", "dev")
    app.config.from_object(config[env])  # config dict is from api/config.py

    # initialize Neo4j 
    from api.models.base import db
    db.init_app(app, config[env].DATABASE_URI, config[env].DATABASE_USER, config[env].DATABASE_PASS)

    # import and register blueprints
    from api.views import main
    app.register_blueprint(main.main)
    app.register_error_handler(Exception, all_exception_handler)

    return app
Ejemplo n.º 4
0
def create_app():

    app = Flask(__name__, static_folder='../static')
    # babel = Babel(app)
    app.config.from_object('api.config.setting')
    app.config.from_object('api.config.secure')
    register_blueprints(app)
    db.init_app(app)
    login_manager.init_app(app)
    migrate = Migrate(app, db)
    register_shell_context(app)
    register_commands(app)
    #要放在db.init之后,不然会提示:sqlalchemy.exc.InvalidRequestError: When initializing mapper Mapper|Suggestions|suggestions, expression 'Reply' failed to locate a name ("name
    # 'Reply' is not defined"). If this is a class name, consider adding this relationship() to the <class 'api.models.Suggestions.Suggestions'> ass after both dependent classes have been defined.
    # from api.admin import admin
    # admin.init_app(app)

    #向jinjia注册自定义函数
    env = app.jinja_env
    env.filters['int_to_datetime'] = int_to_datetime

    return app
Ejemplo n.º 5
0
def create_app(config: Config) -> Flask:
    """
    Flask application factory
    """
    # configuration
    app.config.from_object(config)

    # register blueprints
    app.register_blueprint(auth)
    app.register_blueprint(insurance)

    # auth
    JWT(app, authenticate, identity)

    # database
    db_url = app.config['SQLALCHEMY_DATABASE_URI']
    if not database_exists(db_url):
        create_database(db_url)

    db.init_app(app)
    with app.app_context():
        db.create_all()
        db.session.commit()
    return app