0
0
Flaskframework~20 mins

Form field types in Flask - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Form Field Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the rendered HTML output of this Flask-WTF form field?

Consider this Flask-WTF form field definition:

from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired

class MyForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])

What HTML does the name field render by default?

A<input id="name" name="name" type="text" value="">
B<input id="name" name="name" type="password" value="">
C<textarea id="name" name="name"></textarea>
D<input id="name" name="name" type="email" value="">
Attempts:
2 left
💡 Hint

Think about the default HTML input type for a StringField in Flask-WTF.

📝 Syntax
intermediate
2:00remaining
Which option correctly defines a Flask-WTF IntegerField with a minimum value validator?

You want to create a form field that accepts only integers greater than or equal to 10. Which code snippet correctly defines this field?

Aage = IntegerField('Age', validators=[NumberRange(min=10)])
Bage = IntegerField('Age', validators=[DataRequired(min=10)])
Cage = IntegerField('Age', validators=[Length(min=10)])
Dage = IntegerField('Age', validators=[InputRequired(min=10)])
Attempts:
2 left
💡 Hint

Look for the validator that checks numeric ranges.

state_output
advanced
2:00remaining
What is the value of the form field after submission with empty input?

Given this Flask-WTF form:

from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import DataRequired

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])

If the user submits the form with the username field left empty, what will be the value of form.username.data after form.validate_on_submit() is called?

ARaises a ValidationError
BNone
CAn empty string ('')
DThe string 'None'
Attempts:
2 left
💡 Hint

Think about how WTForms handles empty text input fields.

🔧 Debug
advanced
2:00remaining
Why does this Flask-WTF form field raise a TypeError?

Examine this form field definition:

from wtforms import SelectField

class MyForm(FlaskForm):
    choice = SelectField('Choose', choices='yes,no,maybe')

When rendering or validating, a TypeError occurs. Why?

ASelectField requires a default value, missing here.
BThe <code>choices</code> argument must be a list of tuples, not a string.
CThe field name 'choice' is a reserved keyword causing the error.
DSelectField cannot be used without a validator.
Attempts:
2 left
💡 Hint

Check the expected type for the choices parameter.

🧠 Conceptual
expert
2:00remaining
Which Flask-WTF field type should you use for a form input that accepts multiple file uploads?

You want users to upload several files at once in your Flask form. Which field type is best suited for this?

ATextAreaField with file URLs
BFileField with <code>multiple=True</code> attribute
CStringField with comma-separated file paths
DMultipleFileField
Attempts:
2 left
💡 Hint

Look for a field type designed specifically for multiple files.