defroute(self, rule, **options): """Like :meth:`Flask.route` but for a blueprint. The endpoint for the :func:`url_for` function is prefixed with the name of the blueprint. """
defadd_url_rule(self, rule, endpoint=None, view_func=None, **options): """Like :meth:`Flask.add_url_rule` but for a blueprint. The endpoint for the :func:`url_for` function is prefixed with the name of the blueprint. """ if endpoint: assert"."notin endpoint, "Blueprint endpoints should not contain dots" if view_func and hasattr(view_func, "__name__"): assert ( "."notin view_func.__name__ ), "Blueprint view function name should not contain dots" self.record(lambda s: s.add_url_rule(rule, endpoint, view_func, **options))
defrecord(self, func): if self._got_registered_once and self.warn_on_modifications: from warnings import warn
warn( Warning( "The blueprint was already registered once " "but is getting modified now. These changes " "will not show up." ) ) self.deferred_functions.append(func)
if blueprint.name in self.blueprints: assert self.blueprints[blueprint.name] is blueprint, ( "A name collision occurred between blueprints %r and %r. Both" ' share the same name "%s". Blueprints that are created on the' " fly need unique names." % (blueprint, self.blueprints[blueprint.name], blueprint.name) ) else: self.blueprints[blueprint.name] = blueprint self._blueprint_order.append(blueprint) first_registration = True