Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask class.
Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'App' instead of 'Flask' will cause an import error.
Trying to import 'Database' or 'Model' from flask is incorrect.
✗ Incorrect
The Flask class is imported from the flask package to create the app instance.
2fill in blank
mediumComplete the code to create a Flask app instance.
Flask
app = [1](__name__) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Application' or 'App' will cause a NameError.
Using 'create_app' is a pattern but not the class constructor.
✗ Incorrect
The Flask class is called with __name__ to create the app instance.
3fill in blank
hardFix the error in the code to initialize SQLAlchemy with the app.
Flask
db = SQLAlchemy()
db.[1](app) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'initialize' or 'start' causes AttributeError.
Using 'create' is not a method of SQLAlchemy instance.
✗ Incorrect
The method to link the SQLAlchemy object to the Flask app is init_app.
4fill in blank
hardFill both blanks to define a simple model with an id primary key and a name column.
Flask
class User(db.Model): id = db.Column(db.[1], primary_key=True) name = db.Column(db.[2](50))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using Text for id causes errors.
Using Float for name is incorrect.
✗ Incorrect
The id column uses Integer type and is primary key. The name column uses String with max length 50.
5fill in blank
hardFill all three blanks to create tables in the database after app context is pushed.
Flask
with app.[1](): db.[2]() print('[3] tables created!')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'App' instead of 'app_context' causes errors.
Calling 'create' instead of 'create_all' misses table creation.
✗ Incorrect
Use app_context() to push context, then call create_all() to create tables, and print a confirmation message.