I'm reading http://pythonhosted.org/WTForms/ but nowhere does it define the interface to a filter function, as in the filters= keyword argument to the Field() constructor. Elsewhere it says that the .filter attribute is a list of callables. So what is the calling sequence? Does it take one argument and return the filtered value? Should it raise some exception if the argument isn't valid, and if so, what exception(s)?
Basically,
class MyForm(Form):
myfield = wtf.TextField('My field', filters=[lambda x: x])
The filter
argument is a sequence (tuple or list) of callables accepting the input value of the field and returns the transformed value. You can chain multiple filters sequentially.
Note that the filter shown in the example above does nothing: it returns the raw input value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With