0
0
Djangoframework~30 mins

Why settings configuration matters in Django - See It in Action

Choose your learning style9 modes available
Why settings configuration matters
📖 Scenario: You are building a simple Django project that needs to handle different environments like development and production. Proper settings configuration helps your project behave correctly in each environment.
🎯 Goal: Create a Django settings file with a base configuration, add a variable to switch between development and production modes, and use that variable to set the debug mode accordingly.
📋 What You'll Learn
Create a dictionary called BASE_SETTINGS with keys INSTALLED_APPS and DATABASES and their exact values
Add a variable called ENVIRONMENT with the value 'development'
Use an if statement to set DEBUG to True if ENVIRONMENT is 'development', else False
Add a final setting ALLOWED_HOSTS as an empty list
💡 Why This Matters
🌍 Real World
In real projects, settings configuration helps your Django app behave correctly in different environments like development, testing, and production.
💼 Career
Understanding settings configuration is essential for Django developers to deploy apps safely and efficiently.
Progress0 / 4 steps
1
Create base settings dictionary
Create a dictionary called BASE_SETTINGS with these exact entries: 'INSTALLED_APPS' set to a list containing 'django.contrib.admin' and 'django.contrib.auth', and 'DATABASES' set to a dictionary with key 'default' mapping to another dictionary with 'ENGINE' set to 'django.db.backends.sqlite3' and 'NAME' set to 'mydatabase'.
Django
Need a hint?

Use a dictionary with keys 'INSTALLED_APPS' and 'DATABASES'. The 'INSTALLED_APPS' value is a list of two strings. The 'DATABASES' value is a nested dictionary.

2
Add environment variable
Add a variable called ENVIRONMENT and set it to the string 'development'.
Django
Need a hint?

Just create a variable named ENVIRONMENT and assign it the string 'development'.

3
Set debug mode based on environment
Use an if statement to set a variable called DEBUG to True if ENVIRONMENT is equal to 'development', otherwise set DEBUG to False.
Django
Need a hint?

Use a simple if-else block comparing ENVIRONMENT to 'development' to set DEBUG.

4
Add allowed hosts setting
Add a variable called ALLOWED_HOSTS and set it to an empty list [].
Django
Need a hint?

Just create an empty list variable named ALLOWED_HOSTS.