pallets/flask · error · ValueError

'name' may not be empty.

Error message

'name' may not be empty.

What it means

A ValueError from `Blueprint.__init__` (src/flask/sansio/blueprints.py:195-196). The blueprint `name` is the first positional argument and becomes the prefix for every endpoint the blueprint registers (`name.view`) and the key in `app.blueprints`; an empty or falsy name would produce unaddressable endpoints and an unusable registry key, so Flask rejects it at construction time.

Source

Thrown at src/flask/sansio/blueprints.py:196

        static_folder: str | os.PathLike[str] | None = None,
        static_url_path: str | None = None,
        template_folder: str | os.PathLike[str] | None = None,
        url_prefix: str | None = None,
        subdomain: str | None = None,
        url_defaults: dict[str, t.Any] | None = None,
        root_path: str | None = None,
        cli_group: str | None = _sentinel,  # type: ignore[assignment]
    ):
        super().__init__(
            import_name=import_name,
            static_folder=static_folder,
            static_url_path=static_url_path,
            template_folder=template_folder,
            root_path=root_path,
        )

        if not name:
            raise ValueError("'name' may not be empty.")

        if "." in name:
            raise ValueError("'name' may not contain a dot '.' character.")

        self.name = name
        self.url_prefix = url_prefix
        self.subdomain = subdomain
        self.deferred_functions: list[DeferredSetupFunction] = []

        if url_defaults is None:
            url_defaults = {}

        self.url_values_defaults = url_defaults
        self.cli_group = cli_group
        self._blueprints: list[tuple[Blueprint, dict[str, t.Any]]] = []

    def _check_setup_finished(self, f_name: str) -> None:
        if self._got_registered_once:

View on GitHub ↗ (pinned to 6a2f545bfd)

Solutions

  1. Pass a non-empty literal name: `Blueprint('admin', __name__)`.
  2. If the name is computed, validate it before constructing the blueprint and fail with context (which module produced the empty name).
  3. Derive a fallback from the import name explicitly, e.g. `name or import_name.rsplit('.', 1)[-1]`, only if that's genuinely intended.

Example fix

# before
bp = Blueprint("", __name__)

# after
bp = Blueprint("admin", __name__)
Defensive patterns

Strategy: validation

Validate before calling

name = name.strip()
if not name:
    raise ValueError('Blueprint name must be non-empty')
bp = Blueprint(name, __name__)

Type guard

def is_valid_bp_name(name):
    return isinstance(name, str) and bool(name.strip()) and '.' not in name

Prevention

When it happens

Trigger: `Blueprint('', __name__)`, or passing `None`/any falsy value as the name — e.g. `Blueprint(some_var, __name__)` where `some_var` came back empty from config, an env var, or a string operation like `module.split('.')[-1]` on unexpected input.

Common situations: Programmatically generating blueprints in a plugin loader where the derived name is empty; swapping the argument order and passing an empty default; refactoring that moved the name into a variable that isn't populated yet at import time.

Related errors


AI-assisted analysis of pallets/flask@6a2f545bfd (2026-07-31). Data as JSON: /data/errors/9d8c7bc874d02585.json. Report an issue: GitHub ↗.