django中是否有任何属性或类似占位符的东西,我可以在其中编写永久文本

Is there any attribute or something like placeholder in django, where I can write the permanent text

我正在做一个简单的表格。我正在搜索 Django 中的任何术语,例如占位符,但是 'placeholder text' 会随着用户在文本框中键入内容而消失。我想要 django-text-field 中的 'permanent text' 之类的东西,当用户打开表单时,他们必须在我在编码时输入的 'permanent text' 之后开始写一些东西。

永久文本应保留在用户输入的位置,而不是像占位符文本那样逐渐消失。

是的,你可以。 在您的 form.py 中,您可以使用 widget.

添加所有 css 属性
class OrganizationForm(forms.Form):

    class Meta:
        model = Organization
        fields = ('org_about', 'org_pic')

    org_about = forms.CharField(
        label='About Organization',
        required=False,
        widget = forms.Textarea(
            attrs={
                'class': 'form-control valid',
                'onfocus': 'this.placeholder = ''',
                'onblur': "this.placeholder = 'About Your organization'",
                'type':'text',
                'placeholder': 'About Your organization',
                'rows': 5,
                'cols': 15,
                'value': 'about organization',

            }
        )
    )

查看有关 widgets 的更多详细信息 here

据我所知,没有办法完全符合您的要求。我分享了一个您可以通过这种方式实现的想法:

input {
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="30"><text x="5" y="19" style="font: bold 16px Arial;">Age:</text></svg>') no-repeat;
  border: 1px solid #555;
  box-sizing: border-box;
  font: 16px "Arial";
  height: 30px;
  padding-left: 50px;
  width: 300px;
}
<input type="text" />
more details 此外,您可以使用:before :after css 效果来实现您想要的。