python
data_error
ai_generated
true
django.core.exceptions.ValidationError: ['选择一个有效的选项。5不是可用选项之一。']
django.core.exceptions.ValidationError: ['Select a valid choice. 5 is not one of the available choices.']
ID: python/django-form-invalid-choice
80%修复率
86%置信度
0证据数
2024-02-14首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 3.x | active | — | — | — |
根因分析
带有choices的表单字段接收到不在choices列表中的值。
English
Form field with choices receives a value not in the choices list.
解决方案
-
95% 成功率
Ensure the submitted value is in the choices: if value in dict(choices): ...
-
90% 成功率
Use a ModelChoiceField for dynamic choices.
无效尝试
常见但无效的做法:
-
80% 失败
May not be a valid option; hardcoding invalid values.
-
70% 失败
Loses functionality; users cannot select valid options.