gpt4 book ai didi

python - 如何去除标签?

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:28 25 4
gpt4 key购买 nike

如何从模板中的MultipleChoiceField中删除标签?

enter image description here

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/

25 4 0