我尝试更改django表单中的字段标签,并且还想添加占位符但是当我设置占位符属性时,字段标签不起作用并显示默认字段标签&#34 ; work_or_study"而不是" Bio"。 这是代码:
class ProfileEditForm(forms.ModelForm):
date_of_birth=forms.CharField(widget=forms.TextInput(attrs={'placeholder':'y-m-d'}))
work_or_study=forms.CharField(widget=forms.TextInput(attrs={'placeholder':'something interesting about you'}))
class Meta:
model= Profile
labels = {"work_or_study":"Bio"}
fields = ('date_of_birth','work_or_study')
答案 0 :(得分:0)
修复标签更改此
work_or_study=forms.CharField(widget=forms.TextInput(attrs={'placeholder':'something interesting about you'}))
到
work_or_study=forms.CharField(label="Bio", widget=forms.TextInput(attrs={'placeholder':'something interesting about you'}))
并删除Meta
中的标签列表