Skip to content

Instantly share code, notes, and snippets.

Created July 6, 2015 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9ec5d6fc507b4027505b to your computer and use it in GitHub Desktop.
Save anonymous/9ec5d6fc507b4027505b to your computer and use it in GitHub Desktop.
import os
from flask import Flask
def create_app(config_file=None, config_object=None):
"""
Bootstrap the flask application, registering blueprints, modules and other fun things.
:param config_file: a python file containing key/values variables
:param config_object: a python object (can be a dict) containing key/values variables
:return: the app object
"""
app = Flask(__name__, static_folder='public')
# Configuration
app.config.from_object('my_app.settings.BaseConfig')
app.environment = os.getenv('MY_APP_ENV', 'dev')
if config_file:
app.config.from_pyfile(config_file)
if config_object:
app.config.update(**config_object)
from custom_class import custom_class
custom_class.init_app(app)
return app
class CustomClass(object):
app = None
config = None
def __init__(self, app=None):
if app:
self.init_app(app)
def init_app(self, app):
self.app = app
self.config = self.app.config['CUSTOM_CLASS']
# Init anything else
custom_class = CustomClass()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment