Created
January 26, 2016 13:10
-
-
Save takwas/1ef2b3f0fad040a5927d to your computer and use it in GitHub Desktop.
Should all imports in a function come at the top of the function?
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
def create_app(config_key): | |
""" | |
A factory function to create a Flask application instance and do | |
some initializations. | |
""" | |
# import `config_dict` dictionary from configuration module: | |
# `config.py` | |
from config import config_dict | |
configuration = config_dict.get(config_key) | |
print "Config %s " % config_key ####DEBUG | |
try: | |
app = Flask(configuration.APP_NAME) | |
except AttributeError: | |
app = Flask(__name__) | |
# Get the configuration settings for this application instance | |
app.config.from_object(configuration) | |
# Let's know the mode the app is running in. Create object of config | |
# instance to get its string representation | |
print 'Initializing app ...\nMode:\t%r' % configuration() ####DEBUG | |
# Initialize flask-extensions. Call <init_app> method on each | |
# extension's instance | |
configuration.init_app(app, bootstrap, db, login_manager) | |
# Pass objects into Jinja2 environment globals | |
import utils | |
jinja_env = app.jinja_env | |
jinja_env.globals['isinstance'] = isinstance | |
jinja_env.globals['utils'] = utils |
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
def create_app(config_key): | |
""" | |
A factory function to create a Flask application instance and do | |
some initializations. | |
""" | |
# standard library imports | |
from inspect import getmembers, isfunction | |
# local imports | |
from helpers import utils | |
from config import config_dict | |
configuration = config_dict.get(config_key) | |
try: | |
app = Flask(configuration.APP_NAME) | |
except AttributeError: | |
app = Flask(__name__) | |
# Get the configuration settings for this application instance | |
app.config.from_object(configuration) | |
# Let's know the mode the app is running in. Create object of config | |
# instance to get its string representation | |
print 'Initializing app ...\nMode:\t%r' % configuration() ####DEBUG | |
# Initialize flask-extensions. Call <init_app> method on each | |
# extension's instance | |
configuration.init_app(app, bootstrap, db, login_manager) | |
# Pass some needed objects into Jinja2 environment globals | |
jinja_env = app.jinja_env | |
jinja_env.globals['isinstance'] = isinstance | |
jinja_env.globals['utils'] = utils |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment