python - 如何去除标签?

标签 python html django python-3.x django-1.10

如何从模板中的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/

相关文章:

javascript - 用 django 和 sql 实现实时倒计时时钟?

python - django modelAdmin 显示标题

python - 如何在一个git项目中开发多个pip包?

python - 生成包含另一个 NumPy 数组索引的 NumPy 数组

python - 在 OpenErp 7 中查询对象

javascript - 使用 jQuery 保持被点击的文章处于跟踪/活跃状态

html - 电子邮件模板 : text-decoration: none; NOT working

python - 数字列表的校验和

.net - F# 与 IronPython : When is one preferred to the other?

javascript - 如何有选择地附加圆圈?