def create_app(config_obj=None, **kwargs): """Sets config from passed in config object, initializes Flask modules, registers blueprints (routes) Args: config_obj (class): config class to apply to app Returns: app: configured and initialized Flask app object """ app = Flask(__name__, static_folder=None) if not config_obj: logging.warning("No config specified; defaulting to development") import config config_obj = config.DevelopmentConfig app.config.from_object(config_obj) from src.models.base import db, migrate db.init_app(app) db.app = app migrate.init_app(app, db) from src.routes import register_routes register_routes(app) if kwargs.get("celery", False): init_celery(kwargs["celery"], app) return app
def create_app(): load_dotenv() app = Flask(__name__, static_folder='static') app.config.from_object('settings') db.init_app(app) login_manager.init_app(app) migrate.init_app(app, db) jwt.init_app(app) WEBHOOK.init_app(app) CORS(app) init_celery(celery, app) from models import Course, User, Invite, TokenList @jwt.user_identity_loader def user_identity_lookup(user): return user.username @jwt.user_loader_callback_loader def user_loader_callback(identity): return User.query.filter_by(username=identity).first() @jwt.user_loader_error_loader def custom_user_loader_error(identity): ret = {"msg": "User {} not found".format(identity)} return jsonify(ret), 404 @jwt.token_in_blacklist_loader def check_token(token): return TokenList.is_revoked(token) from views.users import schemas from views.courses import schemas from views.invites import schemas @app.route("/") def hello(): return "hello" from views.auth import auth app.register_blueprint(auth, url_prefix="/auth") from views.courses import courses app.register_blueprint(courses, url_prefix='/courses') from views.users import user app.register_blueprint(user, url_prefix="/users") from views.invites import invites app.register_blueprint(invites, url_prefix="/invites") from views.projects import projects app.register_blueprint(projects, url_prefix="/projects") from views.stats import stats app.register_blueprint(stats, url_prefix="/stats") from views import webhook return app
from app import celery, create_app from celery_utils import init_celery init_celery(celery, create_app())
import config from celery_utils import init_celery, celery from src import create_app app = create_app(config.DevelopmentConfig) init_celery(celery, app)
def create_app(app_name=PKG_NAME, **kwargs): app = Flask(app_name) if kwargs.get("celery"): init_celery(kwargs.get("celery"), app)