0
0
Djangoframework~10 mins

Environment-based settings in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the environment variable module.

Django
import os
SECRET_KEY = os.environ.get([1])
Drag options to blanks, or click blank then click option'
A'SECRET_KEY'
B"DEBUG"
CSECRET_KEY
DDEBUG
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the environment variable name.
Using variable names without quotes.
2fill in blank
medium

Complete the code to set DEBUG mode from environment variable.

Django
DEBUG = os.environ.get([1], 'False') == 'True'
Drag options to blanks, or click blank then click option'
ADEBUG
C"SECRET_KEY"
D'DEBUG'
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted variable names.
Confusing variable names.
3fill in blank
hard

Fix the error in loading ALLOWED_HOSTS from environment variable.

Django
ALLOWED_HOSTS = os.environ.get([1], '').split(',')
Drag options to blanks, or click blank then click option'
AALLOWED_HOSTS
B'ALLOWED_HOSTS'
C"DEBUG"
Dallowed_hosts
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted variable names.
Using wrong variable names.
4fill in blank
hard

Fill both blanks to load database settings from environment variables.

Django
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': os.environ.get([1]),
        'USER': os.environ.get([2]),
    }
}
Drag options to blanks, or click blank then click option'
A'DB_NAME'
B'DB_USER'
C'DATABASE_NAME'
D'DATABASE_USER'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong environment variable names.
Forgetting quotes around variable names.
5fill in blank
hard

Fill all three blanks to set email backend settings from environment variables.

Django
EMAIL_BACKEND = os.environ.get([1], 'django.core.mail.backends.smtp.EmailBackend')
EMAIL_HOST = os.environ.get([2], 'localhost')
EMAIL_PORT = int(os.environ.get([3], '25'))
Drag options to blanks, or click blank then click option'
A'EMAIL_BACKEND'
B'EMAIL_HOST'
C'EMAIL_PORT'
D'EMAIL_USER'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong or inconsistent environment variable names.
Not quoting the environment variable names.