如何在django中同时添加占位符和更改表单字段标签?

时间:2017-11-18 17:13:39

标签: python django django-forms django-templates

我尝试更改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')

1 个答案:

答案 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

中的标签列表