Created
October 26, 2016 19:50
-
-
Save christabor/7b7ee54e784c03bf376e9bdab45f95d7 to your computer and use it in GitHub Desktop.
Flask app module toggling
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
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) |
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
from flask import Blueprint | |
svc_a = Blueprint('svc_a', __name__) |
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
"""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