【问题标题】:How to add placeholder and change form field label simultaneously in django?如何在 django 中同时添加占位符和更改表单字段标签?
【发布时间】:2017-11-18 17:13:38
【问题描述】:

我正在尝试更改 django 表单中的字段标签,并且还想添加一个占位符,但是当我设置占位符属性时,字段标签不起作用并显示默认字段标签“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')

【问题讨论】:

    标签: python django django-forms django-templates


    【解决方案1】:

    修复标签更改此

    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 中的标签列表

    【讨论】:

      猜你喜欢
      • 2020-11-29
      • 2017-10-23
      • 2012-11-11
      • 2018-05-04
      • 2016-10-04
      • 2020-12-27
      • 2019-10-09
      • 2022-12-17
      • 1970-01-01
      相关资源
      最近更新 更多