Bird
0
0

How should you correctly assign a secret key to a Flask app instance?

easy📝 Syntax Q3 of 15
Flask - Security Best Practices
How should you correctly assign a secret key to a Flask app instance?
Aapp.config['SESSION_KEY'] = 'secret'
Bapp.config['SECRET'] = 'mysecret'
Capp.secret = '12345'
Dapp.secret_key = 'a_very_secure_random_string'
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct attribute

    Flask expects the secret key to be set via app.secret_key or app.config['SECRET_KEY'].
  2. Step 2: Check options

    Only app.secret_key = 'a_very_secure_random_string' uses the correct attribute app.secret_key with a proper string.
  3. Final Answer:

    app.secret_key = 'a_very_secure_random_string' -> Option D
  4. Quick Check:

    Use secret_key attribute or config key [OK]
Quick Trick: Use app.secret_key or config['SECRET_KEY'] [OK]
Common Mistakes:
MISTAKES
  • Using wrong config keys like 'SECRET' or 'SESSION_KEY'
  • Assigning to non-existent attributes
  • Using weak or empty strings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Flask Quizzes