0
0
Flaskframework~10 mins

Flask-Login extension - 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 Flask-Login extension.

Flask
from flask_login import [1]
Drag options to blanks, or click blank then click option'
AFlaskLogin
BLoginManager
CLoginHandler
DUserLogin
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect class names like FlaskLogin or UserLogin.
2fill in blank
medium

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

Flask
login_manager = [1]()
login_manager.init_app(app)
Drag options to blanks, or click blank then click option'
ALoginManager
BUserManager
CSessionManager
DAuthManager
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong class names like UserManager or AuthManager.
3fill in blank
hard

Fix the error in the user loader function decorator.

Flask
@login_manager.[1]
def load_user(user_id):
    return User.get(user_id)
Drag options to blanks, or click blank then click option'
Aload
Buser
Clogin
Duser_loader
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@login_manager.load_user_loader' or '@login_manager.load_user'.
4fill in blank
hard

Fill both blanks to protect a route so only logged-in users can access it.

Flask
@app.route('/dashboard')
@[1]
def dashboard():
    return 'Welcome to your dashboard!'

Drag options to blanks, or click blank then click option'
Alogin_required
Blogin_manager
Cuser_loader
Dlogin_user
Attempts:
3 left
💡 Hint
Common Mistakes
Using '@login_manager' or '@user_loader' as decorators for routes.
5fill in blank
hard

Fill all three blanks to log in a user after verifying credentials.

Flask
from flask_login import [1]

@app.route('/login', methods=['POST'])
def login():
    user = User.query.filter_by(username=request.form['username']).first()
    if user and user.check_password(request.form['password']):
        [2](user)
        return redirect([3])
    return 'Invalid credentials', 401
Drag options to blanks, or click blank then click option'
Alogin_user
Curl_for('dashboard')
Dlogout_user
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'logout_user' instead of 'login_user'.
Not redirecting after login.