'I want to know how to add placeholder to Django Modelforms?

I want to know how to add placeholder to Django modelform fields I have pasted here code from my models.py file and forms.py file enter image description here

enter image description here



Solution 1:[1]

There are two ways to achieve the results that you want .

But the simplest way is to add placeholder to the form field in Django is by following line of code :

comment = forms.CharField(max_length=200, placeholder="Text!")

And for your case It will be something like :

widgets= {
       'title' : forms.TextInput(placeholder="this is my placeholder"),

and so on for all fields.

Hope it will resolve the issue. Else let me know.

and please remove attrs keyword argument from forms field because it is causing issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Utkarsh verma