Sometimes, we want to add a placeholder on a CharField in Python Django.
In this article, we’ll look at how to add a placeholder on a CharField in Python Django.
How to add a placeholder on a CharField in Python Django?
To add a placeholder on a CharField in Python Django, we can use the forms.CharField class.
For instance, we write
q = forms.CharField(label='search',
widget=forms.TextInput(attrs={'placeholder': 'Search'}))
in our form class to create the q CharField.
We set the placeholder of the CharField by setting the attrs argument to {'placeholder': 'Search'}.
Conclusion
To add a placeholder on a CharField in Python Django, we can use the forms.CharField class.