Bird
0
0

What issue exists in this settings.py snippet?

medium📝 Debug Q6 of 15
Django - Deployment and Production
What issue exists in this settings.py snippet?
import os
DEBUG = os.getenv('DEBUG', False)

Assuming the environment variable DEBUG is not set, what will be the type and value of DEBUG?
ADEBUG is a boolean False
BDEBUG is a string 'False'
CDEBUG is a boolean True
DDEBUG is None
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.getenv default

    The default value passed is the boolean False.
  2. Step 2: os.getenv returns strings or default as is

    Since the environment variable is missing, os.getenv returns the default False (boolean).
  3. Step 3: But environment variables are strings

    When environment variable is set, it returns a string, so DEBUG can be string or boolean depending on env.
  4. Step 4: Potential inconsistency

    Mixing types can cause bugs; better to always treat as string and convert explicitly.
  5. Final Answer:

    DEBUG is a boolean False -> Option A
  6. Quick Check:

    Default value type is preserved [OK]
Quick Trick: os.getenv returns default as-is, watch types [OK]
Common Mistakes:
MISTAKES
  • Assuming os.getenv always returns string
  • Not handling type conversion explicitly
  • Confusing default value type with env var type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes