Flask app with "submodules"
You can use the following project structure:
app api -todo -__init__.py -other_apis.py -newsletter -__init__.py -other_apis.py __init__.py
In the app.api.todo.__init__.py
:
from flask import Blueprinttodo = Blueprint("todo", __name__)
In the app.api.newsletter.__init__.py
:
from flask import Blueprintnewsletter = Blueprint("newsletter", __name__)
In the app.__init__.py
:
from flask import FLaskapp = Flask(__name__)from app.api.todo import todofrom app.api.newsletter import newsletterapp.register_blueprint(todo, url_prefix="/api/todo")app.register_blueprint(newsletter, url_prefix="/api/newsletter")if __name__ == "__main__": app.run()
And you can change which blueprint is registered and what url prefix bound to blueprint with environment variable.