Bird
0
0

Consider this snippet in settings.py:

medium📝 Predict Output Q4 of 15
Django - Deployment and Production
Consider this snippet in settings.py:
import os
DEBUG = os.getenv('DEBUG', 'False').lower() == 'true'
print(DEBUG)

If the environment variable DEBUG is set to 'TRUE' (uppercase), what will be the output?
ANone
BFalse
CTrue
DRaises an error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate os.getenv

    The environment variable 'DEBUG' is set to 'TRUE'. The default 'False' is ignored.
  2. Step 2: Apply .lower()

    'TRUE'.lower() becomes 'true'.
  3. Step 3: Compare to 'true'

    'true' == 'true' evaluates to True.
  4. Final Answer:

    True -> Option C
  5. Quick Check:

    Case-insensitive comparison ensures correct boolean [OK]
Quick Trick: Use .lower() to handle case-insensitive env vars [OK]
Common Mistakes:
MISTAKES
  • Assuming 'TRUE' != 'true' without normalization
  • Not converting string to boolean properly
  • Expecting os.getenv to return boolean directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes