def create_app(_run_mode=None): # Create Flask app. global app base_dir = os.path.dirname(os.path.abspath(__file__)) template_dir = os.path.join(base_dir, 'templates') static_dir = os.path.join(base_dir, 'static') app = Flask("procjam15", template_folder=template_dir, static_folder=static_dir) # Dev run mode. if _run_mode == "dev": app.config["DEBUG"] = True app.config["SECRET_KEY"] = "WeDontCareAboutSecretsInDev" # Heroku run mode. elif _run_mode == "heroku": # Get port number and secret key from Heroku environment variable. app.config["PORT_NR"] = int(os.environ["PORT"]) app.config["SECRET_KEY"] = os.environ["FLASK_SECRET_KEY"] app.config["DEBUG"] = False init_stdout_handler() set_up_logger(app.logger) # Dreamhost run mode. elif _run_mode == "dreamhost": # Get port number and secret key from Heroku environment variable. app.config["SECRET_KEY"] = os.environ["FLASK_SECRET_KEY"] app.config["DEBUG"] = False init_stdout_handler() set_up_logger(app.logger) # Unrecognized run mode. else: logging.error("Did not recognize run mode '%s'." % _run_mode) return None app.debug = app.config["DEBUG"] # Import the views, to apply the decorators which use the global app object. import main.views # Set up Jinja 2 filters. set_up_jinja_filters(app) return app
def create_app(_run_mode=None): # Create Flask app global app template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app = Flask("application", template_folder=template_dir) # Load kill switches # app.config["APP_KILL_CACHE"] = os.environ.get("APP_KILL_CACHE", False) # Load default configuration app.config.from_object("application.default_config") # Dev run mode if _run_mode == "dev": app.config["DEBUG"] = True app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" # Replace with local DB app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False # Otherwise this gets annoying real fast DebugToolbarExtension(app) # Test run mode elif _run_mode == "test": app.config["DEBUG"] = True app.config["TESTING"] = True app.config["WTF_CSRF_ENABLED"] = False # Or CSRF checks will fail # app.config["APP_KILL_CACHE"] = True app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" # Production run mode elif _run_mode == "production": # Get additional configuration based on run environment run_environment = os.environ.get("APP_RUN_ENV", "local") if run_environment == "heroku": # Get configuration data from Heroku environment variables app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL") elif run_environment == "vagrant": app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" # Replace with local DB set_up_logging(app) # Unrecognized run mode else: logging.error("Did not recognize run mode '%s'" % _run_mode) return None, None # Initialize the database global db import application.models db.init_app(app) # Initialize other Flask extensions # Import the views, to apply the decorators which use the global app object. import application.views # Register blueprints # from application.widget import widget_blueprint # app.register_blueprint(widget_blueprint) # Set up Jinja 2 filters set_up_jinja_filters(app) return app, db
def create_app(_run_mode=None): # Create Flask app global app template_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app = Flask("application", template_folder=template_dir) # Load kill switches # app.config["APP_KILL_CACHE"] = os.environ.get("APP_KILL_CACHE", False) # Load default configuration app.config.from_object("application.default_config") # Dev run mode if _run_mode == "dev": app.config["DEBUG"] = True app.config[ "SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" # Replace with local DB app.config[ "DEBUG_TB_INTERCEPT_REDIRECTS"] = False # Otherwise this gets annoying real fast DebugToolbarExtension(app) # Test run mode elif _run_mode == "test": app.config["DEBUG"] = True app.config["TESTING"] = True app.config["WTF_CSRF_ENABLED"] = False # Or CSRF checks will fail # app.config["APP_KILL_CACHE"] = True app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" # Production run mode elif _run_mode == "production": # Get additional configuration based on run environment run_environment = os.environ.get("APP_RUN_ENV", "local") if run_environment == "heroku": # Get configuration data from Heroku environment variables app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get( "DATABASE_URL") elif run_environment == "vagrant": app.config[ "SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:" # Replace with local DB set_up_logging(app) # Unrecognized run mode else: logging.error("Did not recognize run mode '%s'" % _run_mode) return None, None # Initialize the database global db import application.models db.init_app(app) # Initialize other Flask extensions # Import the views, to apply the decorators which use the global app object. import application.views # Register blueprints # from application.widget import widget_blueprint # app.register_blueprint(widget_blueprint) # Set up Jinja 2 filters set_up_jinja_filters(app) return app, db