Here are the two ways I know to set a default value for a field using WTForms.
To set the value to be the default for all instances of a form, declare the value in the field's definition.
class ReconForm(Form): compressedFilePath = StringField( 'Compressed File Path', [validators.Required()], default='hi') form = ReconForm()
To verify:
assert 'value="hi"' in str(form.compressedFilePath)
To set the value to be the default for just a specific instance of the form, specify the value at instantiation.
class ReconForm(Form): compressedFilePath = StringField( 'Compressed File Path', [validators.Required()]) form = ReconForm(compressedFilePath='hi')
To verify:
assert 'value="hi"' in str(form.compressedFilePath)