A StringField is a form field used to accept short text input from the user, like names or titles.
Click to reveal answer
beginner
How does a PasswordField differ from a StringField?
A PasswordField hides the input characters for privacy, typically used for passwords, while StringField shows the text as typed.
Click to reveal answer
beginner
What is the purpose of a BooleanField in Flask forms?
A BooleanField represents a checkbox that can be either checked (True) or unchecked (False).
Click to reveal answer
beginner
Explain the use of SelectField in Flask forms.
SelectField lets users pick one option from a dropdown list of choices.
Click to reveal answer
beginner
What kind of input does a TextAreaField accept?
TextAreaField accepts multi-line text input, useful for comments or messages.
Click to reveal answer
Which Flask-WTF field type is best for a user to enter their email address?
AStringField
BBooleanField
CPasswordField
DSelectField
✗ Incorrect
Email addresses are short text, so StringField is suitable.
Which field type hides the input characters as you type?
ATextAreaField
BPasswordField
CBooleanField
DStringField
✗ Incorrect
PasswordField hides input for privacy.
If you want users to select one option from a list, which field should you use?
APasswordField
BBooleanField
CStringField
DSelectField
✗ Incorrect
SelectField provides a dropdown list for single choice.
Which field type is best for a user to write a long message?
ASelectField
BBooleanField
CTextAreaField
DStringField
✗ Incorrect
TextAreaField allows multi-line text input.
What does a BooleanField represent in a form?
AA checkbox
BA text input
CA dropdown list
DA password input
✗ Incorrect
BooleanField is a checkbox that can be checked or unchecked.
List and describe five common Flask-WTF form field types and their typical uses.
Think about different ways users enter data in forms.
You got /5 concepts.
Explain when you would use a SelectField instead of a StringField in a Flask form.
Consider user choices and input control.
You got /4 concepts.
Practice
(1/5)
1. Which Flask-WTF form field type should you use to collect a user's password securely?
easy
A. StringField
B. PasswordField
C. BooleanField
D. SelectField
Solution
Step 1: Understand the purpose of each field type
PasswordField is designed to mask input for passwords, unlike StringField which is plain text.
Step 2: Match the field to the requirement
Since passwords need to be hidden when typed, PasswordField is the correct choice.
Final Answer:
PasswordField -> Option B
Quick Check:
Password input uses PasswordField [OK]
Hint: Use PasswordField for hidden password input [OK]
Common Mistakes:
Using StringField for passwords exposes text
Choosing BooleanField or SelectField for password input
Confusing PasswordField with FileField
2. Which of the following is the correct way to declare a checkbox field in a Flask-WTF form?
easy
A. checkbox = BooleanField('Accept Terms')
B. checkbox = StringField('Accept Terms')
C. checkbox = PasswordField('Accept Terms')
D. checkbox = SelectField('Accept Terms')
Solution
Step 1: Identify the field type for checkboxes
BooleanField is used for true/false inputs like checkboxes.
Step 2: Verify the syntax
BooleanField('Accept Terms') correctly declares a checkbox with label 'Accept Terms'.
Final Answer:
checkbox = BooleanField('Accept Terms') -> Option A
Quick Check:
Checkbox uses BooleanField [OK]
Hint: Checkboxes use BooleanField in Flask-WTF [OK]
Common Mistakes:
Using StringField for checkboxes
Confusing SelectField with BooleanField
Incorrect field initialization syntax
3. Given this Flask-WTF form snippet:
class MyForm(FlaskForm):
color = SelectField('Favorite Color', choices=[('r', 'Red'), ('g', 'Green'), ('b', 'Blue')])
form = MyForm()
print(form.color.data)
What will be printed if the user selects 'Green' and submits the form?
medium
A. 'Green'
B. None
C. 'g'
D. 'color'
Solution
Step 1: Understand SelectField choices format
Choices are tuples where first value is the actual data, second is the label shown.
Step 2: Identify the data returned on selection
Selecting 'Green' returns the first element of the tuple: 'g'.
Final Answer:
'g' -> Option C
Quick Check:
SelectField returns choice key, not label [OK]
Hint: SelectField returns the choice key, not the label [OK]
Common Mistakes:
Assuming the label is returned instead of the key
Confusing field name with data
Expecting None if form not submitted
4. What is wrong with this Flask-WTF form field declaration?
class UploadForm(FlaskForm):
file = FileField('Upload File', validators=[DataRequired()])
medium
A. FileField cannot have validators
B. Label 'Upload File' is not allowed
C. FileField should be StringField
D. Missing import for DataRequired validator
Solution
Step 1: Check validator usage
DataRequired is a validator that must be imported from wtforms.validators.
Step 2: Identify missing import
If DataRequired is not imported, this code will raise a NameError.
Final Answer:
Missing import for DataRequired validator -> Option D
Quick Check:
Validators need proper imports [OK]
Hint: Always import validators before using them [OK]
Common Mistakes:
Assuming FileField can't have validators
Using wrong field type for file uploads
Ignoring import errors
5. You want to create a Flask-WTF form that asks for a user's birthdate and a yes/no confirmation if they agree to terms. Which combination of field types is correct?
hard
A. DateField for birthdate and BooleanField for agreement
B. StringField for birthdate and SelectField for agreement
C. PasswordField for birthdate and BooleanField for agreement
D. FileField for birthdate and StringField for agreement
Solution
Step 1: Choose appropriate field for date input
DateField is designed to handle date inputs like birthdate.
Step 2: Choose field for yes/no confirmation
BooleanField is perfect for true/false inputs like agreement checkboxes.
Final Answer:
DateField for birthdate and BooleanField for agreement -> Option A
Quick Check:
DateField + BooleanField = correct combo [OK]
Hint: Use DateField for dates and BooleanField for yes/no [OK]
Common Mistakes:
Using StringField for dates causes format issues
Using PasswordField for non-password inputs
Confusing FileField with date or boolean inputs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.