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

- **ID:** `python/flask-jinja-undefined-attribute`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

Template references a key that is missing from the context dict, or uses dot notation on a dict key that doesn't exist.

## Version Compatibility

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

## Workarounds

1. **** (90% success)
   ```
   Use dict .get with default in template:
{{ user.get('username', 'anon') }}
   ```
2. **** (92% success)
   ```
   Ensure the view passes the key:
return render_template('p.html', user={'username': u.name})
   ```

## Dead Ends

- **** — StrictUndefined makes it raise louder, not fix the missing key. (95% fail)
- **** — If user is a dict without 'username', the attribute access still raises inside the block. (60% fail)
