How I can register Flask Blueprints from my config like apps in Django?
I would like to define Blueprints in the configuration file, which will be automatically registered
#config.py
BLUEPRINTS = (
'news',
'files',
)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I actually have been sketching out something like that in a project tentatively named Hip Pocket. It’s basically the same answer as @HighCat has given you, except it uses Python’s packaging system rather than a
config.pyfile (although it could be extended to autoload from a config file instead – issues and pull requests are most welcome.)So in Hip Pocket you’d do this (see
hip_pocket.tasksfor how it works):autoloadwalks a package (named “apps” by default, although you can change it by passing in the keyword argapps_package) looking forflask.Blueprintobjects to register on the application (by default it looks for a symbol namedroutesin a module namedroutesin each sub package it finds but those defaults can be changed as well.) Your folder layout might look like this:Alternately, if you want to use a config based loader, you could just do this: