Flask - Can't override default subdomain for blueprints needing a different subdomain Flask - Can't override default subdomain for blueprints needing a different subdomain flask flask

Flask - Can't override default subdomain for blueprints needing a different subdomain


What's missing is the subdomain_matching option for Flask():

subdomain_matching – consider the subdomain relative to SERVER_NAME when matching routes. Defaults to False.

Since app is a relative name, you need to set this to True:

app = Flask(__name__, subdomain_matching=True)

This used to be done implicitly, but as of Flask 1.0 it's an explicit switch. The change was made because different people had different expectations of what setting SERVER_NAME means, see Flask issue #998.

As for where you set the subdomain option, that's your choice. If you are reusing blueprints in different contexts, then it makes more sense to set the subdomain option in the app.register_blueprint() call, while setting it in the Blueprint() instance call may make it more self-documenting if you are creating that blueprint object closer to your routes for and so want to make it clearer to someone working on that code that they are affecting a specific subdomain only.