# jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'username'

- **ID:** `python/jinja2-undefined-error`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Template references a variable or attribute that was not passed to render_template or does not exist on the provided object.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.1.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   Use `{{ user.username if user else '' }}` or pass a default: `render_template('x.html', user=user or {})`.
   ```
2. **** (85% success)
   ```
   Enable ChainableUndefined: `app.jinja_env.undefined = jinja2.ChainableUndefined` to allow nested access without raising.
   ```

## Dead Ends

- **** — Undefined has no __bool__ short-circuit before attribute access; still raises. (85% fail)
- **** — Default already is Undefined; needs ChainableUndefined or StrictUndefined change, not reassignment. (70% fail)
