Take this very simple form for example:
class SearchForm(Form):
q = forms.CharField(label='search')
This gets rendered in the template:
<input type="text" name="q" id="id_q" />
However, I want to add the placeholder
attribute to this field with a value of Search
so that the HTML would look something like:
<input type="text" name="q" id="id_q" placeholder="Search" />
Preferably I would like to pass the placeholder value in to CharField
in the form class through a dictionary or something like:
q = forms.CharField(label='search', placeholder='Search')
What would be the best way to accomplish this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…