Allow running Flask Blueprints alongside Superset (#2337)

* Allowing environments to import Blueprints

* Docs entry

* Fix typos
This commit is contained in:
Maxime Beauchemin 2017-03-03 17:09:54 -08:00 committed by GitHub
parent e35016f07d
commit f6ffc00748
3 changed files with 38 additions and 0 deletions

View File

@ -377,3 +377,28 @@ your environment.::
npm run build
cd $SUPERSET_HOME
python setup.py install
Blueprints
----------
`Blueprints are Flask's reusable apps <http://flask.pocoo.org/docs/0.12/blueprints/>`_.
Superset allows you to specify an array of Blueprints
an array of Blueprints in your ``superset_config`` module. Here's
an example on how this can work with a simple Blueprint. By doing
so, you can expect Superset to serve a page that says "OK"
at the ``/simple_page`` url. This can allow you to run other things such
as custom data visualization applications alongside Superset, on the
same server.
..code ::
from flask import Blueprint
simple_page = Blueprint('simple_page', __name__,
template_folder='templates')
@simple_page.route('/', defaults={'page': 'index'})
@simple_page.route('/<page>')
def show(page):
return "Ok"
BLUEPRINTS = [simple_page]

View File

@ -29,6 +29,14 @@ app = Flask(__name__)
app.config.from_object(CONFIG_MODULE)
conf = app.config
for bp in conf.get('BLUEPRINTS'):
try:
print("Registering blueprint: '{}'".format(bp.name))
app.register_blueprint(bp)
except Exception as e:
print("blueprint registration failed")
logging.exception(e)
if conf.get('SILENCE_FAB'):
logging.getLogger('flask_appbuilder').setLevel(logging.ERROR)

View File

@ -286,6 +286,11 @@ if not CACHE_DEFAULT_TIMEOUT:
# permission management
SILENCE_FAB = True
# Integrate external Blueprints to the app by passing them to your
# configuration. These blueprints will get integrated in the app
BLUEPRINTS = []
try:
if CONFIG_PATH_ENV_VAR in os.environ:
# Explicitly import config module that is not in pythonpath; useful