Skip to content

Instantly share code, notes, and snippets.

@christabor
Created October 26, 2016 19:50
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 christabor/7b7ee54e784c03bf376e9bdab45f95d7 to your computer and use it in GitHub Desktop.
Save christabor/7b7ee54e784c03bf376e9bdab45f95d7 to your computer and use it in GitHub Desktop.
Flask app module toggling
from flask import Flask
import settings
from service_a import svc_a as svc_a_bp
app = Flask('myapp')
if settings.SERVICES['serviceA'].enabled:
app.register_blueprint(svc_a_bp)
@app.context_processor
def ctx():
"""Also toggle services in templates etc."""
return dict(services=settings.SERVICES)
from flask import Blueprint
svc_a = Blueprint('svc_a', __name__)
"""Enable flask apps and namespace them easily and safely."""
from collections import namedtuple
Service = namedtuple('Service', 'enabled name admins api_url contact_email')
SERVICES = {
'serviceA': Service(
enabled=True,
admins=[],
api_url='https://servicea.foo.com',
contact_email='askdf@foo.com',
),
'serviceB': Service(
#...You get the idea
),
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment