0
0
Flaskframework~10 mins

Extension initialization pattern 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 create a Flask extension instance.

Flask
from flask_sqlalchemy import SQLAlchemy

db = [1]()
Drag options to blanks, or click blank then click option'
ASQLAlchemy
BFlask
CFlaskApp
DApp
Attempts:
3 left
💡 Hint
Common Mistakes
Using Flask instead of SQLAlchemy to create the extension instance.
Forgetting the parentheses to call the class.
2fill in blank
medium

Complete the code to initialize the extension with the Flask app.

Flask
from flask import Flask

app = Flask(__name__)
db = SQLAlchemy()
db.[1](app)
Drag options to blanks, or click blank then click option'
Arun_app
Binit_app
Cstart_app
Dcreate_app
Attempts:
3 left
💡 Hint
Common Mistakes
Using run_app or start_app which do not exist.
Trying to pass the app to the extension constructor instead of using init_app.
3fill in blank
hard

Fix the error in the extension initialization pattern by completing the blank.

Flask
from flask import Flask
from flask_mail import Mail

mail = Mail()
app = Flask(__name__)
[1] = app
mail.init_app(app)
Drag options to blanks, or click blank then click option'
Amail
Bmail_app
CMail
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning the extension instance instead of the Flask app.
Using a variable name that is not defined.
4fill in blank
hard

Fill both blanks to complete the factory function initializing the extension.

Flask
from flask import Flask
from flask_migrate import Migrate

migrate = Migrate()

def create_app():
    app = Flask(__name__)
    migrate.[1](app, [2])
    return app
Drag options to blanks, or click blank then click option'
Ainit_app
Bdb
Capp
Dstart
Attempts:
3 left
💡 Hint
Common Mistakes
Using start instead of init_app.
Passing the app twice or passing the wrong variable.
5fill in blank
hard

Fill all three blanks to complete the extension initialization with app factory pattern.

Flask
from flask import Flask
from flask_login import LoginManager

login_manager = LoginManager()

def create_app():
    app = Flask(__name__)
    login_manager.[1](app)
    login_manager.login_view = '[2]'
    login_manager.login_message_category = '[3]'
    return app
Drag options to blanks, or click blank then click option'
Ainit_app
Blogin
Cinfo
Dhome
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to call init_app.
Setting login_view to a wrong or non-existent route.
Using an incorrect message category.