Multiple subdomains allowed in the same blueprint
Don't define the blueprint's prefix and subdomain where you are doing it currently, define it like so:
mod = Blueprint('landing', __name__)
Then, simply register the blueprint two times, one for each subdomain:
app.register_blueprint(mod, subdomain='pt', url_prefix='/')app.register_blueprint(mod, subdomain='br', url_prefix='/')
EDIT:
The problem with the given solution, as stated by OP, is that the first registered blueprint will take priority when using url_for
in templates.
A quick workaround could be doing something like this when registering:
app.register_blueprint(mod, subdomain='br')mod.name = 'landing_pt' app.register_blueprint(mod, subdomain='pt')
Note that the order this is done with is important (first register one, then change the name, then register the other one).
Then, for url_for
to work as expected with both subdomains, it is important to use relative redirects like url_for('.index')
instead of url_for('landing.index')
.
By changing the name of the blueprint for the second registration we trick Flask into thinking this is a different blueprint.
Suggestions welcome to better this kind of dirty workaround.