Created
April 10, 2017 02:53
-
-
Save MOOOWOOO/9a287ab375a0fa9fcaa9a3a30e795e94 to your computer and use it in GitHub Desktop.
flask auto blueprint register
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
# coding: utf-8 | |
__author__ = 'Jux.Liu' | |
# (folder, blueprint, prefix) | |
INSTALLED_MODULES = [ | |
('routes', 'main', '/'), | |
('api', 'api', '/api'), | |
('routes', 'store', '/') | |
] | |
def register_blueprint(app): | |
from importlib import import_module | |
for folder, module, prefix in INSTALLED_MODULES: | |
m = import_module(folder) | |
print(m) | |
print(module) | |
if hasattr(m, module): | |
bp = getattr(m, module) | |
if prefix.strip() == '/': | |
# no prefix | |
app.register_blueprint(bp) | |
else: | |
app.register_blueprint(bp, url_prefix=prefix) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment