Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the Flask class correctly.
Flask
from flask import [1] app = [1](__name__)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Request instead of Flask
Using lowercase flask instead of Flask
✗ Incorrect
The Flask class is imported from the flask module to create the app instance.
2fill in blank
mediumComplete the code to push the application context manually.
Flask
with app.[1](): # code that needs app context pass
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request_context instead of app_context
Forgetting to use the context manager 'with'
✗ Incorrect
The app_context() method pushes the application context so you can access app-specific variables.
3fill in blank
hardFix the error in accessing the current app inside a function.
Flask
from flask import [1] def get_name(): return [1].name
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request or session instead of current_app
Trying to access app directly without context
✗ Incorrect
The current_app proxy gives access to the app instance within the application context.
4fill in blank
hardFill both blanks to create and push an application context manually.
Flask
ctx = app.[1]() ctx.[2]() # push context
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request_context instead of app_context
Calling pop instead of push
✗ Incorrect
You create the context with app_context() and push it with push().
5fill in blank
hardFill all three blanks to access the app config inside an application context.
Flask
from flask import [1] with app.[2](): secret = [3].config['SECRET_KEY']
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using request_context instead of app_context
Trying to access app.config directly without context
✗ Incorrect
You import current_app to access the app inside the context created by app_context().