9

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)?

1 Answer 1

6

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.