Tuesday, July 31, 2012

Unbound Forms vs. Bound Forms - The difference is in the constructor arguments.


https://docs.djangoproject.com/en/dev/ref/forms/api/




BoundField.errors
A list-like object that is displayed as an HTML <ul class="errorlist"> when printed:
>>> data = {'subject': 'hi', 'message': '', 'sender': '', 'cc_myself': ''}
>>> f = ContactForm(data, auto_id=False)


data var is as above.


BoundField.value()
New in Django 1.3: Please see the release notes
Use this method to render the raw value of this field as it would be rendered by a Widget:


>>> initial = {'subject': 'welcome'}
>>> unbound_form = ContactForm(initial=initial)
>>> bound_form = ContactForm(data, initial=initial)
>>> print(unbound_form['subject'].value())
welcome
>>> print(bound_form['subject'].value())
hi


unbound form
bound form takes argument dict "data".



No comments:

Post a Comment