pallets/flask · error · NoAppException

Failed to find attribute

Error message

Failed to find attribute {name!r} in {module.__name__!r}.

What it means

Raised by find_app_by_string when the parsed name does not exist on the module (getattr raises AttributeError). The FLASK_APP target resolved to a name the module doesn't define.

Solutions

  1. Use the correct attribute name: export FLASK_APP='module:app'.
  2. Verify the attribute exists with python -c 'import module; print(dir(module))'.
  3. Rename the app variable to match FLASK_APP or vice versa.

Example fix

// before
# export FLASK_APP='module:application'  # module defines 'app' -> raises
// after
# export FLASK_APP='module:app'
Defensive patterns

Strategy: validation

Validate before calling

if not hasattr(module, name):
    raise AttributeError(f'Module {module.__name__!r} has no attribute {name!r}')

Type guard

def module_has_attr(module, name) -> bool:
    return hasattr(module, name)

Try / catch

try:
    app = find_app_by_string(module, app_name)
except NoAppException:
    # verify attribute name and retry
    raise

Prevention

When it happens

Trigger: export FLASK_APP='module:application' where module only defines app, or any typo'd attribute name.

Common situations: Wrong attribute name after the colon; renamed the app variable but didn't update FLASK_APP; module-level circular import hiding the attribute.

Related errors


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

Appendix: source

Thrown at src/flask/cli.py:170

                kw.arg: ast.literal_eval(kw.value)
                for kw in expr.keywords
                if kw.arg is not None
            }
        except ValueError:
            # literal_eval gives cryptic error messages, show a generic
            # message with the full expression instead.
            raise NoAppException(
                f"Failed to parse arguments as literal values: {app_name!r}."
            ) from None
    else:
        raise NoAppException(
            f"Failed to parse {app_name!r} as an attribute name or function call."
        )

    try:
        attr = getattr(module, name)
    except AttributeError as e:
        raise NoAppException(
            f"Failed to find attribute {name!r} in {module.__name__!r}."
        ) from e

    # If the attribute is a function, call it with any args and kwargs
    # to get the real application.
    if inspect.isfunction(attr):
        try:
            app = attr(*args, **kwargs)
        except TypeError as e:
            if not _called_with_wrong_args(attr):
                raise

            raise NoAppException(
                f"The factory {app_name!r} in module"
                f" {module.__name__!r} could not be called with the"
                " specified arguments."
            ) from e
    else:

View on GitHub (pinned to 3596b1ab61)