pallets/flask · error · ValueError

'view_func' name may not contain a dot '.' character.

Error message

'view_func' name may not contain a dot '.' character.

What it means

Blueprint.add_url_rule also checks the view function's __name__ for a dot (when endpoint is not explicitly given, Flask would derive the endpoint from __name__, so a dotted __name__ causes the same collision). If view_func has __name__ containing '.', it raises ValueError. This commonly happens with functools.partial or nested functions.

Solutions

  1. Pass an explicit undotted endpoint= so Flask does not derive one from __name__.
  2. Rename the function so __name__ has no dot, or set view_func.__name__ to a clean identifier before registering.
  3. For partials/wrappers, wrap with functools.wraps to a function whose __name__ is a plain identifier.

Example fix

// before
bp.add_url_rule('/run', view_func=functools.partial(handler, x=1))

// after
bp.add_url_rule('/run', endpoint='run', view_func=functools.partial(handler, x=1))
Defensive patterns

Strategy: type-guard

Validate before calling

def safe_bp_add_url_rule(bp, rule, view_func=None, endpoint=None, **opts):
    if view_func is not None and hasattr(view_func, '__name__') and '.' in view_func.__name__:
        endpoint = endpoint or view_func.__name__.split('.')[-1]
    bp.add_url_rule(rule, endpoint=endpoint, view_func=view_func, **opts)

Type guard

def view_name_is_dot_free(view_func) -> bool:
    name = getattr(view_func, '__name__', None)
    return name is None or '.' not in name

Prevention

When it happens

Trigger: Passing a functools.partial as the view (its __name__ is absent/odd); a lambda or nested function whose __name__ contains a dot; a callable class instance or wrapped function whose __name__ includes a module path; view decorated in a way that sets a dotted __name__.

Common situations: Using @functools.wraps incorrectly leaving a dotted name; passing methods of a class (someclass.handler) as views; decorated views whose wrapper preserved a fully-qualified name.

Related errors


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

Appendix: source

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

    def add_url_rule(
        self,
        rule: str,
        endpoint: str | None = None,
        view_func: ft.RouteCallable | None = None,
        provide_automatic_options: bool | None = None,
        **options: t.Any,
    ) -> None:
        """Register a URL rule with the blueprint. See :meth:`.Flask.add_url_rule` for
        full documentation.

        The URL rule is prefixed with the blueprint's URL prefix. The endpoint name,
        used with :func:`url_for`, is prefixed with the blueprint's name.
        """
        if endpoint and "." in endpoint:
            raise ValueError("'endpoint' may not contain a dot '.' character.")

        if view_func and hasattr(view_func, "__name__") and "." in view_func.__name__:
            raise ValueError("'view_func' name may not contain a dot '.' character.")

        self.record(
            lambda s: s.add_url_rule(
                rule,
                endpoint,
                view_func,
                provide_automatic_options=provide_automatic_options,
                **options,
            )
        )

    @t.overload
    def app_template_filter(self, name: T_template_filter) -> T_template_filter: ...
    @t.overload
    def app_template_filter(
        self, name: str | None = None
    ) -> t.Callable[[T_template_filter], T_template_filter]: ...
    @setupmethod

View on GitHub (pinned to 3596b1ab61)