如何从模板中的MultipleChoiceField中删除标签?
forms.py:
class RequirementAddForm(forms.ModelForm):
symbol = forms.MultipleChoiceField(required=False, widget=forms.CheckboxSelectMultiple, choices=REQUIREMENTS_CHOICES,)
class Meta:
model = Requirement
fields = ('symbol',)
template.html:
{{ form }}
最佳答案
以下是一些可能的解决方案
1) 在表单定义中使用label=""
2) 如果您使用继承的表单并且没有直接访问权限,请覆盖标签
def __init__(self, *args, **kwargs):
super(FormClass, self).__init__(*args, **kwargs)
self.fields['field'].label = ''
另一个可能的选择是传递 auto_id=False
进入表格
关于python - 如何去除标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43593232/