Bird
0
0

You wrote this in settings.py:

medium📝 Debug Q14 of 15
Django - Deployment and Production
You wrote this in settings.py:
import os
SECRET_KEY = os.getenv('SECRET_KEY')
DEBUG = os.getenv('DEBUG', False)
But DEBUG is always True even when you set DEBUG=False in the environment. What is the problem?
Aos.getenv returns strings, so DEBUG is the string 'False', which is truthy
Bos.getenv cannot read boolean environment variables
CSECRET_KEY must be set before DEBUG
DYou must import dotenv to use os.getenv
Step-by-Step Solution
Solution:
  1. Step 1: Understand os.getenv returns strings

    Environment variables are strings, so os.getenv('DEBUG', False) returns string 'False' if set.
  2. Step 2: Recognize string 'False' is truthy in Python

    Non-empty strings are True in boolean context, so DEBUG is always True.
  3. Final Answer:

    os.getenv returns strings, so DEBUG is the string 'False', which is truthy -> Option A
  4. Quick Check:

    Env vars are strings; 'False' string is True in boolean [OK]
Quick Trick: Remember env vars are strings, not booleans [OK]
Common Mistakes:
MISTAKES
  • Assuming os.getenv returns boolean type
  • Thinking import order affects env var reading
  • Believing dotenv is required for os.getenv

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes