如果定義的藍(lán)圖比較多,導(dǎo)入藍(lán)圖是一件很惡心的事情,
可以使用werkzeug中的 方法進(jìn)行批量導(dǎo)入。 如下:
# recursive the blueprint and all api.
def register_blueprints(root, app):
for name in find_modules(root, recursive=True):
module = import_string(name)
if hasattr(module, 'bp'):
app.register_blueprint(module.bp)
def create_app():
app = Flask(__name__)
app.config.from_object(config)
# multi blueprint
register_blueprints('app.views', app)
return app