Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using seconds instead of minutes
Forgetting to use timedelta
Setting the wrong number of minutes
✗ Incorrect
The session lifetime is set using timedelta with the number of minutes. Here, 30 minutes is the correct value.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a method instead of a property
Using incorrect property names
Not setting the property to True
✗ Incorrect
To make a session permanent in Flask, set session.permanent = True inside the route.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using datetime instead of timedelta
Using undefined classes like time or duration
Not importing timedelta
✗ Incorrect
The correct class to set session lifetime is timedelta from datetime module.
4fill in blank
hardFill 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'
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
✗ Incorrect
The secret key is set with 'SECRET_KEY' and session lifetime with 'PERMANENT_SESSION_LIFETIME'.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing datetime instead of timedelta
Using wrong config key for secret
Not setting session.permanent to True
✗ Incorrect
Import timedelta, set SECRET_KEY, and mark session.permanent = True to make session permanent.