Skip to content

Instantly share code, notes, and snippets.

@MOOOWOOO
Created April 10, 2017 02:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOOOWOOO/9a287ab375a0fa9fcaa9a3a30e795e94 to your computer and use it in GitHub Desktop.
Save MOOOWOOO/9a287ab375a0fa9fcaa9a3a30e795e94 to your computer and use it in GitHub Desktop.
flask auto blueprint register
# 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