pallets/flask · error · ValueError

'name' may not be empty.

Error message

'name' may not be empty.

What it means

Blueprint.__init__ requires a non-empty name; the name becomes the URL/endpoint prefix and is used as a dict key, so an empty string is rejected with ValueError. The check is `if not name`, so None, '', and other falsy values all trip it.

Solutions

  1. Pass a non-empty, unique name as the first positional argument to Blueprint.
  2. If the name comes from config, validate it is a non-empty string before constructing the Blueprint.
  3. Use the module's __name__ convention: Blueprint(__name__.split('.')[-1]) but guard against empty results.

Example fix

// before
bp = Blueprint('')

// after
bp = Blueprint('admin')
Defensive patterns

Strategy: validation

Validate before calling

def validate_bp_name(name: str) -> str:
    if not name:
        raise ValueError('Blueprint name required')
    return name

Type guard

def is_valid_bp_name(name) -> bool:
    return isinstance(name, str) and bool(name)

Prevention

When it happens

Trigger: Constructing Blueprint('') or Blueprint(name) where name is computed as an empty string; passing name=None; deriving name from a filename/module that yielded empty.

Common situations: Programmatic blueprint generation from a config value that is missing/empty; refactoring that accidentally passes import_name as the first positional twice or drops the name; copy-paste leaving the name blank.

Related errors


AI-assisted analysis of pallets/flask@3596b1ab61 (2026-08-11). Data as JSON: /api/errors/9d8c7bc874d02585. Report an issue: GitHub.

Appendix: 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 3596b1ab61)