0
0
Flaskframework~10 mins

Session lifetime 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 set the session lifetime to 30 minutes in Flask.

Flask
from flask import Flask
from datetime import timedelta
app = Flask(__name__)
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=[1])
Drag options to blanks, or click blank then click option'
A60
B30
C15
D45
Attempts:
3 left
💡 Hint
Common Mistakes
Using seconds instead of minutes
Forgetting to use timedelta
Setting the wrong number of minutes
2fill in blank
medium

Complete the code to make the session permanent in a Flask route.

Flask
from flask import session
@app.route('/')
def index():
    session.[1] = True
    return 'Session is permanent'
Drag options to blanks, or click blank then click option'
Apermanence
Bmake_permanent
Cset_permanent
Dpermanent
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method instead of a property
Using incorrect property names
Not setting the property to True
3fill in blank
hard

Fix the error in setting the session lifetime to 1 hour in Flask.

Flask
app.config['PERMANENT_SESSION_LIFETIME'] = [1](hours=1)
Drag options to blanks, or click blank then click option'
Atime
Bdatetime
Ctimedelta
Dduration
Attempts:
3 left
💡 Hint
Common Mistakes
Using datetime instead of timedelta
Using undefined classes like time or duration
Not importing timedelta
4fill in blank
hard

Fill both blanks to set a secret key and session lifetime to 15 minutes in Flask.

Flask
app = Flask(__name__)
app.config['[1]'] = 'mysecretkey'
app.config['[2]'] = timedelta(minutes=15)
Drag options to blanks, or click blank then click option'
ASECRET_KEY
BSESSION_KEY
CPERMANENT_SESSION_LIFETIME
DSESSION_LIFETIME
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong config keys like SESSION_KEY or SESSION_LIFETIME
Mixing up the order of config keys
Not setting SECRET_KEY
5fill in blank
hard

Fill all three blanks to create a Flask app, set a secret key, and make the session permanent with a 10-minute lifetime.

Flask
from flask import Flask, session
from datetime import [1]
app = Flask(__name__)
app.config['[2]'] = 'secret123'
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(minutes=10)
@app.route('/')
def home():
    session.[3] = True
    return 'Session set to permanent'
Drag options to blanks, or click blank then click option'
Atimedelta
BSECRET_KEY
Cpermanent
Ddatetime
Attempts:
3 left
💡 Hint
Common Mistakes
Importing datetime instead of timedelta
Using wrong config key for secret
Not setting session.permanent to True