Host Matching

New in version 2.1.3.

Kyoukai comes with built-in support for Werkzeug host matching:

# enable host matching in the tree
# this needs to be set on the root blueprint for the blueprint tree
app = Kyoukai("my_website", host_matching=True)

# set a host on a sub-blueprint
# all sub-blueprints of `bp` will now use the host ``
bp = Blueprint("api", host="")

As shown above, host matching is easy to enable, requiring only two changes.

  • host_matching MUST be set on the root Blueprint (passed here via the app) - this will enable host matching when building the final map.
  • host is passed into the Blueprint constructor, which specifies the host that will be matched for each route in this Blueprint.

In the example above, all routes registered to bp will only match if the Host header is However, all routes registered to other Blueprints will match on any hosts.

Relation to the Tree

Children Blueprints will copy their host from the parent, unless overridden. So, for example:

# only host match ````
app = Kyoukai("my_website", host="")

# bp1 will only obey requests from ``
bp1 = Blueprint("something")

# bp2 will only obey requests from ``, overriding the global host match
bp2 = Blueprint("something else", host="")

# bp3 however will inherit its parents host matching (bp2)
bp3 = Blueprint("something finally")