def create_app(settings_module): app = Flask(__name__) CORS(app) app.config.from_object(settings_module) # Inicializa las extensiones db.init_app(app) ma.init_app(app) migrate.init_app(app, db) # Captura todos los errores 404 Api(app, catch_all_404s=True) # Deshabilita el modo estricto de acabado de una URL con / app.url_map.strict_slashes = False # Registra los blueprints app.register_blueprint(users_bp) app.register_blueprint(auth_bp) app.register_blueprint(jobs_bp) app.register_blueprint(interviews_bp) app.register_blueprint(applications_bp) app.register_blueprint(stats_bp) app.register_blueprint(companies_bp) app.register_blueprint(rating_bp) app.register_blueprint(categories_bp) # Registra manejadores de errores personalizados register_error_handlers(app) return app
def create_app(config, **kwargs): app = Flask(__name__, **kwargs) cors = CORS(app, resources={r"/api/*": {"origins": "*"}}) app.register_blueprint(api_blueprint) app.config.from_object(config) logging.basicConfig(level=logging.INFO) with app.app_context(): db.init_app(app) db.create_all() default_user() auth_token = app.config.get('AUTH_TOKEN') if len(auth_token) == 0: raise EnvironmentError( 'AUTH_TOKEN is not set. Can not proceed operating without authorization token for the API.' ) elif len(auth_token) < 15: raise Exception( 'AUTH_TOKEN too weak, please use token with more than 14 characters' ) app.secret_key = app.config.get('AUTH_TOKEN') return app
def init_app(app): from flask_migrate import Migrate from app.database.db import db from app.database.seeder import seed_db app.cli.add_command(seed_db) db.init_app(app) Migrate(app, db)
def flask_app(): app = create_app('app.config.Test') from app.database.db import db with app.app_context(): db.init_app(app) db.create_all() yield app
def create_app(): app = Flask(__name__) app.config.from_object(ConfigFactory.factory().__class__) # # init extensions db.init_app(app) migrate.init_app(app, db) ma.init_app(app) # # add custom commands app.cli.add_command(sync_teams) app.cli.add_command(sync_players) app.cli.add_command(sync_seasons) app.cli.add_command(sync_games) app.cli.add_command(sync_new_games) with app.app_context(): # import database models from app.database.models.season import SeasonModel from app.database.models.team import TeamModel from app.database.models.player import PlayerModel from app.database.models.game import GameModel from app.database.models.player_team_season import PlayerSeasonTeamModel from app.database.models.teams_stats import TeamsStatsModel from app.database.models.players_stats import PlayersStatsModel # # import blueprints # views from app.views.home import home_bp from app.views.season import season_bp from app.views.team import team_bp from app.views.player import player_bp from app.views.game import game_bp # register blueprints # views app.register_blueprint(home_bp, url_prefix="/home") app.register_blueprint(season_bp, url_prefix="/api/season") app.register_blueprint(team_bp, url_prefix="/api/team") app.register_blueprint(player_bp, url_prefix="/api/player") app.register_blueprint(game_bp, url_prefix="/api/game") # # end import blueprints return app
def init_app(app): from flask_migrate import Migrate from app.database.db import db db.init_app(app) Migrate(app, db)
from app import app @app.before_first_request def create_tables(): db.create_all() if __name__ == "__main__": # avoid circular imports from app.database.db import db db.init_app(app) app.run(debug=True)