Reputation: 7056
I am trying to use django forms, and I am interested in rending a form with " blank label".
Something like:
class SearchForm(forms.Form):
q = forms.CharField(required=True,widget=forms.TextInput(attrs {'id':'field','name':'field'}),label="Search")
and then I render the form in my html using
{{form.as_p}}
However, I have this annoying "Search:" being displayed on my html, which I dont want. I have tried using just:
q = forms.CharField(required=True,widget=forms.TextInput(attrs {'id':'field','name':'field'}))
but this outputs "Q:", which I guess is the default label. How do I tell django that I do not need the label rendered?
Many thanks.
Upvotes: 0
Views: 2548
Reputation: 49866
You could just do:
class SearchForm(forms.Form):
q = forms.CharField(required=True,widget=forms.TextInput(attrs {'id':'field','name':'field'}),label="")
That will just set the label to the empty string.
Upvotes: 0
Reputation: 6756
Check out this example, it should clarify how to use it: https://docs.djangoproject.com/en/dev/topics/forms/#customizing-the-form-template
Are you sure {{ form.q }} does not work?
Upvotes: 1