class BoundField
[source]
Used to display HTML or access attributes for a single field of a Form
instance.
The __str__()
(__unicode__
on Python 2) method of this object displays the HTML for this field.
To retrieve a single BoundField
, use dictionary lookup syntax on your form using the field’s name as the key:
>>> form = ContactForm() >>> print(form['subject']) <input id="id_subject" type="text" name="subject" maxlength="100" required />
To retrieve all BoundField
objects, iterate the form:
>>> form = ContactForm() >>> for boundfield in form: print(boundfield) <input id="id_subject" type="text" name="subject" maxlength="100" required /> <input type="text" name="message" id="id_message" required /> <input type="email" name="sender" id="id_sender" required /> <input type="checkbox" name="cc_myself" id="id_cc_myself" />
The field-specific output honors the form object’s auto_id
setting:
>>> f = ContactForm(auto_id=False) >>> print(f['message']) <input type="text" name="message" required /> >>> f = ContactForm(auto_id='id_%s') >>> print(f['message']) <input type="text" name="message" id="id_message" required />
Please login to continue.