{
  "id": "python/flask-jinja-undefined-attribute",
  "signature": "jinja2.exceptions.UndefinedError: 'dict object' has no attribute 'username'",
  "signature_zh": "jinja2.exceptions.UndefinedError: 'dict object' 没有属性 'username'",
  "regex": "jinja2\\.exceptions\\.UndefinedError:\\ 'dict\\ object'\\ has\\ no\\ attribute\\ 'username'",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "模板引用了上下文字典中不存在的键，或对不存在的字典键使用了点号访问。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "StrictUndefined makes it raise louder, not fix the missing key.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "If user is a dict without 'username', the attribute access still raises inside the block.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "Use dict .get with default in template:\n{{ user.get('username', 'anon') }}",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.92,
      "how": "Ensure the view passes the key:\nreturn render_template('p.html', user={'username': u.name})",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-04-03",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}