kube-exam/data/sample-api-users/src/__init__.py

39 lines
768 B
Python

import os
from flask import Flask
from flask_bcrypt import Bcrypt
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
# instantiate the db
db = SQLAlchemy()
cors = CORS()
bcrypt = Bcrypt()
def create_app(script_info=None):
# instantiate the app
app = Flask(__name__)
# set config
app_settings = os.getenv("APP_SETTINGS")
app.config.from_object(app_settings)
# set up extensions
db.init_app(app)
cors.init_app(app, resources={r"*": {"origins": "*"}})
# register api
from src.api import api
api.init_app(app)
# shell context for flask cli
@app.shell_context_processor
def ctx():
return {"app": app, "db": db}
with app.app_context():
db.create_all()
return app