我尝试打印出request.POST
中的所有(键,值)对以提取表单数据。我注意到,如果不选中BooleanField(即将其设置为True
),则不包含在request.POST
中。即使将BooleanField设置为required=True
,也是如此。
是否可以强制发送(密钥,对)?例如,在下面的这种形式中,如果在渲染时未选中applied
字段,则request.POST
是否仍应包含applied off
?选中applied
时,request.POST
包含applied on
。但未经检查,applied
不是request.POST
数据的一部分。
class ItemModifierForm(forms.Form):
applied= forms.BooleanField(label='Trait A', required=True)