0
0
Flaskframework~10 mins

Form field types in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the correct form field type for a text input in Flask-WTF.

Flask
from flask_wtf import FlaskForm
from wtforms import [1]

class MyForm(FlaskForm):
    name = [1]('Name')
Drag options to blanks, or click blank then click option'
ABooleanField
BIntegerField
CStringField
DPasswordField
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text input
Using BooleanField for text input
2fill in blank
medium

Complete the code to add a password input field to the form.

Flask
from flask_wtf import FlaskForm
from wtforms import StringField, [1]

class LoginForm(FlaskForm):
    username = StringField('Username')
    password = [1]('Password')
Drag options to blanks, or click blank then click option'
ADateField
BBooleanField
CTextAreaField
DPasswordField
Attempts:
3 left
💡 Hint
Common Mistakes
Using StringField for passwords
Using BooleanField for passwords
3fill in blank
hard

Fix the error in the code by choosing the correct field type for a checkbox.

Flask
from flask_wtf import FlaskForm
from wtforms import StringField, [1]

class SubscribeForm(FlaskForm):
    subscribe = [1]('Subscribe to newsletter')
Drag options to blanks, or click blank then click option'
ATextAreaField
BBooleanField
CIntegerField
DDateField
Attempts:
3 left
💡 Hint
Common Mistakes
Using StringField for checkboxes
Using IntegerField for checkboxes
4fill in blank
hard

Fill both blanks to create a form with a text area and a date input field.

Flask
from flask_wtf import FlaskForm
from wtforms import [1], [2]

class FeedbackForm(FlaskForm):
    comments = [1]('Comments')
    visit_date = [2]('Date of Visit')
Drag options to blanks, or click blank then click option'
ATextAreaField
BDateField
CStringField
DBooleanField
Attempts:
3 left
💡 Hint
Common Mistakes
Using StringField instead of TextAreaField
Using BooleanField for dates
5fill in blank
hard

Fill all three blanks to define a form with an email, integer, and checkbox field.

Flask
from flask_wtf import FlaskForm
from wtforms import [1], [2], [3]

class RegistrationForm(FlaskForm):
    email = [1]('Email')
    age = [2]('Age')
    agree_terms = [3]('Agree to Terms')
Drag options to blanks, or click blank then click option'
AEmailField
BIntegerField
CBooleanField
DStringField
Attempts:
3 left
💡 Hint
Common Mistakes
Using StringField for email
Using StringField for age
Using StringField for checkbox