register() — flask Function Reference
Architecture documentation for the register() function in blueprints.py from the flask codebase.
Entity Profile
Dependency Diagram
graph TD ab08d213_c111_86c1_e5b9_dd3fd7770d86["register()"] 0c59fa87_9a90_f011_4207_98ae96479921["Blueprint"] ab08d213_c111_86c1_e5b9_dd3fd7770d86 -->|defined in| 0c59fa87_9a90_f011_4207_98ae96479921 332767b5_f33c_7d07_a9d2_9d9efe7f8c22["make_setup_state()"] ab08d213_c111_86c1_e5b9_dd3fd7770d86 -->|calls| 332767b5_f33c_7d07_a9d2_9d9efe7f8c22 fcb19d5b_9453_b002_936c_db0309530b8c["_merge_blueprint_funcs()"] ab08d213_c111_86c1_e5b9_dd3fd7770d86 -->|calls| fcb19d5b_9453_b002_936c_db0309530b8c cd459c23_b1c5_45ac_a393_26c2ff268367["get()"] ab08d213_c111_86c1_e5b9_dd3fd7770d86 -->|calls| cd459c23_b1c5_45ac_a393_26c2ff268367 a095b8ad_24db_e31f_c7dd_d94b4dc565d0["add_url_rule()"] ab08d213_c111_86c1_e5b9_dd3fd7770d86 -->|calls| a095b8ad_24db_e31f_c7dd_d94b4dc565d0 style ab08d213_c111_86c1_e5b9_dd3fd7770d86 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/flask/sansio/blueprints.py lines 273–377
def register(self, app: App, options: dict[str, t.Any]) -> None:
"""Called by :meth:`Flask.register_blueprint` to register all
views and callbacks registered on the blueprint with the
application. Creates a :class:`.BlueprintSetupState` and calls
each :meth:`record` callback with it.
:param app: The application this blueprint is being registered
with.
:param options: Keyword arguments forwarded from
:meth:`~Flask.register_blueprint`.
.. versionchanged:: 2.3
Nested blueprints now correctly apply subdomains.
.. versionchanged:: 2.1
Registering the same blueprint with the same name multiple
times is an error.
.. versionchanged:: 2.0.1
Nested blueprints are registered with their dotted name.
This allows different blueprints with the same name to be
nested at different locations.
.. versionchanged:: 2.0.1
The ``name`` option can be used to change the (pre-dotted)
name the blueprint is registered with. This allows the same
blueprint to be registered multiple times with unique names
for ``url_for``.
"""
name_prefix = options.get("name_prefix", "")
self_name = options.get("name", self.name)
name = f"{name_prefix}.{self_name}".lstrip(".")
if name in app.blueprints:
bp_desc = "this" if app.blueprints[name] is self else "a different"
existing_at = f" '{name}'" if self_name != name else ""
raise ValueError(
f"The name '{self_name}' is already registered for"
f" {bp_desc} blueprint{existing_at}. Use 'name=' to"
f" provide a unique name."
)
first_bp_registration = not any(bp is self for bp in app.blueprints.values())
first_name_registration = name not in app.blueprints
app.blueprints[name] = self
self._got_registered_once = True
state = self.make_setup_state(app, options, first_bp_registration)
if self.has_static_folder:
state.add_url_rule(
f"{self.static_url_path}/<path:filename>",
view_func=self.send_static_file, # type: ignore[attr-defined]
endpoint="static",
)
# Merge blueprint data into parent.
if first_bp_registration or first_name_registration:
self._merge_blueprint_funcs(app, name)
for deferred in self.deferred_functions:
deferred(state)
cli_resolved_group = options.get("cli_group", self.cli_group)
if self.cli.commands:
if cli_resolved_group is None:
app.cli.commands.update(self.cli.commands)
elif cli_resolved_group is _sentinel:
self.cli.name = name
app.cli.add_command(self.cli)
else:
self.cli.name = cli_resolved_group
app.cli.add_command(self.cli)
for blueprint, bp_options in self._blueprints:
bp_options = bp_options.copy()
bp_url_prefix = bp_options.get("url_prefix")
bp_subdomain = bp_options.get("subdomain")
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does register() do?
register() is a function in the flask codebase, defined in src/flask/sansio/blueprints.py.
Where is register() defined?
register() is defined in src/flask/sansio/blueprints.py at line 273.
What does register() call?
register() calls 4 function(s): _merge_blueprint_funcs, add_url_rule, get, make_setup_state.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free