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

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

## Root Cause

The template references a variable attribute that is not present in the context dict passed to TemplateResponse.

## Version Compatibility

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

## Workarounds

1. **** (94% success)
   ```
   {{ user.get('username', 'guest') }}
   ```
2. **** (92% success)
   ```
   return templates.TemplateResponse('p.html', {'request': request, 'user': user or {}})
   ```

## Dead Ends

- **** — StrictUndefined makes the error louder, not absent; it does not supply the missing key. (85% fail)
- **** — Hides the bug and returns a broken page. (80% fail)
