Field.label
The label
argument lets you specify the “human-friendly” label for this field. This is used when the Field
is displayed in a Form
.
As explained in “Outputting forms as HTML” above, the default label for a Field
is generated from the field name by converting all underscores to spaces and upper-casing the first letter. Specify label
if that default behavior doesn’t result in an adequate label.
Here’s a full example Form
that implements label
for two of its fields. We’ve specified auto_id=False
to simplify the output:
1 2 3 4 5 6 7 8 9 10 | >>> from django import forms >>> class CommentForm(forms.Form): ... name = forms.CharField(label = 'Your name' ) ... url = forms.URLField(label = 'Your website' , required = False ) ... comment = forms.CharField() >>> f = CommentForm(auto_id = False ) >>> print (f) <tr><th>Your name:< / th><td>< input type = "text" name = "name" required / >< / td>< / tr> <tr><th>Your website:< / th><td>< input type = "url" name = "url" required / >< / td>< / tr> <tr><th>Comment:< / th><td>< input type = "text" name = "comment" required / >< / td>< / tr> |
Please login to continue.