コード例 #1
0
def create_app(config_name):
    app = FlaskAPI(__name__, instance_relative_config=True)
    app.config.from_object(app_config[config_name])
    app.config.from_pyfile('config.py')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    return app
コード例 #2
0
def create_app() -> Flask:
    app = Flask(__name__)

    # Load application settings from environment variable.
    # If environment variable is not set will load development settings by default.
    app_settings = os.getenv("APP_SETTINGS", "settings.DevelopmentConfig")
    env_path = Path(".env.development").absolute()

    if not app_settings:
        raise ValueError('"APP_SETTINGS" environment variable not set')

    if app_settings == "settings.TestingConfig":
        env_path = Path(".env.testing")
    elif app_settings == "settings.ProductionConfig":
        env_path = Path(".env.production")

    # Load environment variables depending on application settings (Dev/Test/Prod)
    load_dotenv(path=env_path)
    app.config.from_object(app_settings)

    # Initialize Flask-SQLAlchemy ORM
    db.init_app(app)
    db.app = app

    # Initialize Flask-Migrate
    Migrate(app, db)

    # Initialize flask_resty api
    api = Api(app, prefix="/api")
    initialize_routes(api)

    # Initialize Flask-Bcrypt
    bcrypt_.init_app(app)

    # Initialize swagger
    template = {
        "components": {
            "securitySchemes": {
                "basicAuth": {
                    "type": "http",
                    "scheme": "basic"
                },
                "bearerAuth": {
                    "type": "http",
                    "scheme": "bearer",
                    "bearerFormat": "JWT",
                },
            }
        }
    }
    Swagger(app, template=template)

    return app
コード例 #3
0
ファイル: __init__.py プロジェクト: juan-deder/backend
def create_app():
    app = Flask(__name__)
    app.config.from_object(config[os.environ.get('FLASK_ENV', 'development')])

    from database.models import db
    db.init_app(app)

    from app.main import main
    app.register_blueprint(main)

    db_cli = AppGroup('db')

    @db_cli.command('init')
    def init():
        db.create_all()

    app.cli.add_command(db_cli)

    return app
コード例 #4
0
def create_app(app_name=PKG_NAME, **kwargs):
    app = Flask(app_name)
    app.config.from_object(os.environ['APP_SETTINGS'])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    if kwargs.get("celery"):
        init_celery(kwargs.get("celery"), app)

    from .app import api_bp
    app.register_blueprint(api_bp, url_prefix='/api')

    from database.models import db, flask_bcrypt
    from database.collections import mongo
    # Initiliaze Database 1
    mongo.init_app(app)

    # Initiliaze Database 2
    db.init_app(app)

    flask_bcrypt.init_app(app)

    return app
コード例 #5
0
def create_app(config=None):
    app = Flask(__name__)
    db.init_app(app)
    app.config.from_pyfile('app.cfg')
    # configure your app...
    return app
コード例 #6
0
reload(sys)
sys.setdefaultencoding('utf-8')
log_roll_handler=RotatingFileHandler('roll.log',maxBytes=1024*1000*10)
log_roll_handler.setFormatter(Formatter(
        '%(asctime)s %(levelname)s: %(message)s '
        '[in %(pathname)s:%(lineno)d]'
))
app = Flask(__name__)
# babel = Babel(app)
# @babel.localeselector
# def get_locale():
#    override = request.args.get('lang')
#    if override:
#        session['lang'] = override
#    return session.get('lang', 'zh_CN')
db.init_app(app)
app.config.from_pyfile('app.cfg')
log_roll_handler.setLevel(logging.DEBUG)
app.logger.addHandler(log_roll_handler)
app.register_blueprint(user_ctrl)
app.register_blueprint(admin_ctrl,url_prefix='/admin2')
app.register_blueprint(admin_project_ctrl,url_prefix='/admin2')
app.register_blueprint(admin_user_ctrl,url_prefix='/admin2')
app.register_blueprint(user_api,url_prefix='/api')
app.register_blueprint(category_api,url_prefix='/api')
app.register_blueprint(project_api,url_prefix="/api")
app.register_blueprint(artist_api,url_prefix="/api")
app.register_blueprint(project_ctrl,url_prefix='/project')
app.register_blueprint(common_ctrl, url_prefix='/comm')
app.register_blueprint(payback_api,url_prefix='/api')
app.register_blueprint(common_api,url_prefix='/api')
コード例 #7
0
ファイル: __init__.py プロジェクト: mskcc/hera-sample-tracker
jwt = JWTManager(app)
CORS(app)

blacklist = set()

##################################### Logging settings ###############################################
log_file_path = ''
if ENV == 'local':
    log_file_path = config_options['log_file_local']
elif ENV == 'prod' or ENV == 'dev':
    log_file_path = config_options['log_file_prod']

LOG.basicConfig(
    level=LOG.INFO,
    filename=log_file_path.format(datetime.datetime.now().date()),
    format='%(asctime)s  %(levelname)-10s %(processName)s  %(name)s %(message)s'
)

##################################### DB Initialization###############################################

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

#################################### APP CONSTANTS ###################################################

#ADMIN_GROUPS = ['AHDHD'] # add another admin group from PM's when available
ADMIN_GROUPS = ['zzPDL_SKI_IGO_DATA', 'GRP_SKI_CMO_WESRecapture']
#ADMIN_GROUPS = ['GRP_SKI_CMO_WESRecapture']
CLINICAL_GROUPS = ['GRP_SKI_CMO_WESRecapture_Clinical']
コード例 #8
0
ファイル: wsgi.py プロジェクト: TheArqsz/zit_crypto
from app import app as application
if __name__ == '__main__':
    from database.models import db
    db.init_app(application)
    with application.app_context():
        db.create_all()
    application.run(threaded=True)
コード例 #9
0
from app import flask_app
from database.models import db, Offer, Product

# NOTE: to be run only when db doesn't exist
if __name__ == "__main__":
    with flask_app.app_context():
        db.init_app(flask_app)
        db.create_all()
コード例 #10
0
from dotenv import load_dotenv
from logging import FileHandler, Formatter, INFO
# -------------------------------------------- #
from database.models import db, Actor, Movie
from views.actor import actor
from views.movie import movie
from views.auth import requires_auth, AuthError

load_dotenv()

api = Flask(__name__)

api.register_blueprint(actor, url_prefix='/api')
api.register_blueprint(movie, url_prefix='/api')

db.init_app(api)
db.app = api

api.config["SQLALCHEMY_DATABASE_URI"] = getenv("DATABASE_URL")
api.debug = True

CORS(api, resources={r"/api/*": {"origins": "*"}})


@api.after_request
def after_request(response):
    response.headers.add("Access-Control-Allow-Headers",
                         "Content-Type,Authorization")
    response.headers.add("Access-Control-Allow-Methods",
                         "GET,PATCH,POST,DELETE,OPTIONS")
    return response
コード例 #11
0
def initialize_db(app):
    db.init_app(app)
    CORS(app)
コード例 #12
0
def init_db(app):
    from database.models import db
    db.init_app(app)
    return db