【问题标题】:How to add Placeholder text in fields with django crispy-forms如何使用 django crispy-forms 在字段中添加占位符文本
【发布时间】:2020-11-11 20:33:48
【问题描述】:

我是 django 的新手,使用crispy-forms 来呈现表单。如何将占位符文本添加到字段中,例如“请输入您的地址”

在我看来.py

class PostCreateView(LoginRequiredMixin, CreateView):

    model = Post 
    fields = ['name', 'address']

在models.py中

class Post(models.Model):
    name = models.CharField(max_length=100, blank="true")
    address = models.CharField(max_length=100, blank="true")
    

【问题讨论】:

  • 你能分享你的html吗?

标签: django django-models django-forms django-crispy-forms


【解决方案1】:

每个输入字段都由 django 给定一个 id;从检查中获取 id - 在 Html 文件中并在某个位置添加一个脚本标签 然后使用这个JS代码

document.getElementbyId('id of the field').setAtribute('placeholder','Your PH')

顺便说一句,使用 google 搜索拼写错误并为他们解决问题

【讨论】:

    猜你喜欢
    • 2012-11-09
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2018-05-04
    • 1970-01-01
    相关资源
    最近更新 更多