Recall & Review
beginner
What are environment variables used for in Django projects?
Environment variables store sensitive data like passwords and API keys outside the code. This keeps secrets safe and makes the app easier to configure across different setups.
Click to reveal answer
beginner
How do you access an environment variable in a Django settings file?
Use Python's
os.environ.get('VARIABLE_NAME') to read the value safely. For example, SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY').Click to reveal answer
beginner
Why should you avoid hardcoding secrets directly in Django settings.py?
Hardcoding secrets risks exposing them if the code is shared or uploaded publicly. Environment variables keep secrets separate and safer.
Click to reveal answer
intermediate
What is a common tool to manage environment variables in Django development?
The
python-dotenv package helps load variables from a .env file into environment variables during development.Click to reveal answer
intermediate
How do environment variables help when deploying Django apps to different environments?
They let you change secrets and settings without changing code. For example, you can use different database passwords for development and production by setting different environment variables.Click to reveal answer
Which Python module is commonly used to read environment variables in Django?
✗ Incorrect
The
os module provides os.environ.get() to access environment variables.Why should secrets not be committed to a public Git repository?
✗ Incorrect
Exposing secrets publicly risks unauthorized access to your app or services.
What file is commonly used to store environment variables locally during development?
✗ Incorrect
A
.env file holds environment variables and is loaded by tools like python-dotenv.Which of these is a benefit of using environment variables for secrets?
✗ Incorrect
Environment variables let you update secrets without changing your code.
In Django, where should you put the code to read environment variables?
✗ Incorrect
Settings.py is the right place to configure secrets and settings from environment variables.
Explain how environment variables improve security and flexibility in Django projects.
Think about why you wouldn't want passwords in your code files.
You got /4 concepts.
Describe the steps to use environment variables for the Django SECRET_KEY.
Focus on setup, reading, and safety.
You got /4 concepts.