Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.