Bound and Unbound Forms: Form Instance is either bound to a set of data, or unbound. If it is bound to a set of data, it is capable of validating that data and rendering the form as HTML with the data displayed in the HTML. If it is unbound , it cannot do validation, because there’s no data to validate, but it can still render the blank form as HTML. To create an unbound Form instance, instantiate the class: sf = SampleForm() To bind data to a form, pass the data as a dictionary as the first parameter to your Form class constructor: data = {'fieldname1': 'ABC', 'fieldname2': 'True, 'fieldname3': '123'} sf = SampleForm(data) In the above dictionary, the keys are the field names, which correspond to the attributes in your Form class and the values are the data you are trying to validate. These will usually be strings, but there is no requirement that they be strings...
Comments
Post a Comment