Created
July 6, 2015 14:57
-
-
Save anonymous/9ec5d6fc507b4027505b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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