0
0
Flaskframework~10 mins

Secret key configuration 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 secret key for a Flask app.

Flask
app = Flask(__name__)
app.secret_key = '[1]'
Drag options to blanks, or click blank then click option'
ATrue
B12345
CNone
D'mysecretkey123'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number instead of a string
Leaving the secret key as None
Using a boolean value
2fill in blank
medium

Complete the code to import the module needed to generate a random secret key.

Flask
import [1]
app.secret_key = os.urandom(24)
Drag options to blanks, or click blank then click option'
Aos
Bsys
Crandom
Dflask
Attempts:
3 left
💡 Hint
Common Mistakes
Importing random instead of os
Importing sys or flask which don't have urandom
3fill in blank
hard

Fix the error in setting the secret key to a byte string.

Flask
app.secret_key = [1]'supersecret'
Drag options to blanks, or click blank then click option'
Arb
B'b'
Cb
Dbr
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around b
Using 'rb' or 'br' which are invalid here
4fill in blank
hard

Fill both blanks to set the secret key from an environment variable.

Flask
import [1]
app.secret_key = os.[2]('SECRET_KEY')
Drag options to blanks, or click blank then click option'
Aos
Bgetenv
Cgetenvs
Denviron
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'getenvs' which does not exist
Using 'environ' directly without calling getenv
5fill in blank
hard

Fill all three blanks to create a Flask app with a secret key from environment or fallback.

Flask
import [1]
app = Flask(__name__)
app.secret_key = os.[2]('SECRET_KEY', [3])
Drag options to blanks, or click blank then click option'
Aos
Bgetenv
C'defaultsecretkey'
D'SECRET_KEY'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the environment variable name as the default value
Not providing a fallback value