Python 选择一个有效的选项。[u';B';,u';T';]不是可用的选项之一
在Django 1.7中获取此错误 Models.py Forms.py Views.pyPython 选择一个有效的选项。[u';B';,u';T';]不是可用的选项之一,python,django,Python,Django,在Django 1.7中获取此错误 Models.py Forms.py Views.py 你能再解释一下这个错误吗?在提交django form I时,出现了这样一个错误:“选择一个有效的选项。[u'B',u'T']不是可用的选项之一。”。我正在使用复选框获取多个值。我删除了以前的答案。似乎只有多个输入才会发生错误,对吗?它是否与单个输入(比如u'B')一起工作?如果您发送多个输入,那么模型中的“hypervisor”字段似乎不支持它。它是charfield类型,可以容纳单个字符串。我不认为(
你能再解释一下这个错误吗?在提交django form I时,出现了这样一个错误:“选择一个有效的选项。[u'B',u'T']不是可用的选项之一。”。我正在使用复选框获取多个值。我删除了以前的答案。似乎只有多个输入才会发生错误,对吗?它是否与单个输入(比如u'B')一起工作?如果您发送多个输入,那么模型中的“hypervisor”字段似乎不支持它。它是charfield类型,可以容纳单个字符串。我不认为(?)可以选择使用布尔字段。我认为保持布尔值,使用单选按钮或将其更改为字符字段以保持下拉列表。
class Customize(models.Model):
CHECK_CHOICES = (
("B", "BHK"),
("T", "BTH"),
("L", "BKL"),
)
RAD_CHOICES = (
(0, "TRUE"),
(1, "FALSE")
)
profile = models.ForeignKey(Profile)
hypervisior = models.CharField(max_length=4, choices=CHECK_CHOICES)
enable_soe = models.BooleanField(choices=RAD_CHOICES,default=True)
harden_file = models.FileField()
param1 = models.CharField(max_length=30, unique=True)
def __unicode__(self):
return self.profile
class CustomizeProfileForm(ModelForm):
def __init__(self,*args,**kwargs):
super(CustomizeProfileForm,self).__init__(*args,**kwargs)
self.fields['hypervisior'] = forms.ChoiceField(choices = Customize.CHECK_CHOICES, widget=forms.CheckboxSelectMultiple, required=False)
self.fields['enable_soe'] = forms.ChoiceField(choices = Customize.RAD_CHOICES, widget=forms.RadioSelect)
class Meta:
model = Customize
exclude = ('profile',)
def edit_profile(request, id):
profile = Profile.objects.get(id=id)
if request.method == 'POST':
customize_form = CustomizeProfileForm(request.POST,{'profile' : profile,'id': id})
if customize_form.is_valid():
return HttpResponseRedirect(reverse('display_profile'))
else:
print "Form is invalid"
else:
customize_form = CustomizeProfileForm()
return render(request,'baas/edit_profile.html', {'form':customize_form,'profile' : profile, 'id': id} )