Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Build a Social Network with Flask Takin' Names Flask-WTF Forms

Hara Gopal K
PLUS
Hara Gopal K
Courses Plus Student 10,027 Points

custom validators

in the given examples (name_exists, email_exists) how do the arguments form and field get passed to the functions?

  1. how does the variable "form" is actually referred the the Form class (we haven't created any instance of it yet..)
  2. is "field" a key word here?

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

How the validators get called is separate from how we attach them to fields. Behind the scenes, there's a method that, effectively, is called on an existing Form instance. It'd do something like:

for validator in field.validators:
    validator(form, field)

(hopefully that's obviously fake code)

We don't care about how that works when we're writing validators. We're concerned only with how to create a validator and get the correct validation.