0
0
Flaskframework~10 mins

Current_user object 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 current_user object from Flask-Login.

Flask
from flask_login import [1]
Drag options to blanks, or click blank then click option'
AUserMixin
Blogin_user
Ccurrent_user
Dlogout_user
Attempts:
3 left
💡 Hint
Common Mistakes
Importing login_user instead of current_user.
Forgetting to import from flask_login.
2fill in blank
medium

Complete the code to check if a user is authenticated using current_user.

Flask
if [1].is_authenticated:
    print("User is logged in")
Drag options to blanks, or click blank then click option'
Auser
Bcurrent_user
Csession
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Using user which is undefined.
Using session or request which do not have is_authenticated.
3fill in blank
hard

Fix the error in accessing the current user's username.

Flask
username = [1].username
Drag options to blanks, or click blank then click option'
Arequest.user
Bsession['user']
Cuser
Dcurrent_user
Attempts:
3 left
💡 Hint
Common Mistakes
Using user which is not defined.
Trying to access user info from session or request incorrectly.
4fill in blank
hard

Fill both blanks to create a dictionary with usernames and emails of authenticated users.

Flask
users_info = {user.[1]: user.[2] for user in users if user.is_authenticated}
Drag options to blanks, or click blank then click option'
Ausername
Bemail
Cid
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using id or password instead of username or email.
Not filtering only authenticated users.
5fill in blank
hard

Fill all three blanks to filter users by authentication and get their usernames in uppercase.

Flask
usernames = [user.[1].[2]() for user in users if user.[3]]
Drag options to blanks, or click blank then click option'
Ausername
Bupper
Cis_authenticated
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using lower instead of upper.
Not checking is_authenticated.
Using wrong attribute names.