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
- Pass an explicit undotted endpoint= so Flask does not derive one from __name__.
- Rename the function so __name__ has no dot, or set view_func.__name__ to a clean identifier before registering.
- 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
- Pass an explicit endpoint= when registering partials/wrappers as blueprint views.
- Use functools.wraps to give wrappers a clean __name__.
- Avoid passing methods of dotted class objects directly as views.
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
- 'endpoint' may not contain a dot '.' character.
- Cannot register a blueprint on itself
- 'name' may not be empty.
- 'name' may not contain a dot '.' character.
- ' ' is not a subclass of Exception. Handlers can only be…
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]: ...
@setupmethodView on GitHub (pinned to 3596b1ab61)