{
  "id": "python/jinja2-undefinederror-user-undefined",
  "signature": "jinja2.exceptions.UndefinedError: 'user' is undefined",
  "signature_zh": "jinja2.exceptions.UndefinedError：'user' 未定义",
  "regex": "jinja2\\.exceptions\\.UndefinedError:\\ 'user'\\ is\\ undefined",
  "domain": "python",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A Jinja2 template references a variable that was not passed to the render context or is None.",
  "root_cause_type": "generic",
  "root_cause_zh": "Jinja2 模板引用了未传递给渲染上下文或为 None 的变量。",
  "versions": [
    {
      "version": "3.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "The default filter only works if the variable is undefined; if user is None, it still prints 'None'.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "This silences the error but may lead to empty output and hides real bugs.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.95,
      "how": "return render_template('index.html', user=current_user)",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.85,
      "how": "{% if user is defined %}{{ user.name }}{% endif %}",
      "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.9,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-03-10",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}