Skip to content

Commit d78cc8e

Browse files
31 - Environment Variables & dotenv
1 parent 0c6a62c commit d78cc8e

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

manage.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
"""Django's command-line utility for administrative tasks."""
33
import os
44
import sys
5-
5+
import dotenv
6+
import pathlib
67

78
def main():
89
"""Run administrative tasks."""
10+
# DOT_ENV_PATH = pathlib.Path() / '.env'
11+
# if DOT_ENV_PATH.exists():
12+
# dotenv.read_dotenv(str(DOT_ENV_PATH))
13+
# else:
14+
# print("No .env found, be sure to make it.")
15+
dotenv.read_dotenv()
916
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trydjango.settings')
1017
try:
1118
from django.core.management import execute_from_command_line

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
django>=3.2,<3.3
2+
django-dotenv

trydjango/settings.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
https://docs.djangoproject.com/en/3.2/ref/settings/
1111
"""
1212

13+
import os
1314
from pathlib import Path
1415

1516
# Build paths inside the project like this: BASE_DIR / 'subdir'.
@@ -20,13 +21,14 @@
2021
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
2122

2223
# SECURITY WARNING: keep the secret key used in production secret!
23-
SECRET_KEY = 'django-insecure-0+dmu6*lky0l743o^=)8-^27tn0)dzoi)6-lzb1i)egsso_84h'
24+
SECRET_KEY = os.environ.get('SECRET_KEY', 'django-insecure-0+dmu6*lky0l743o^=)8-^27tn0)dzoi)6-lzb1i)egsso_84h')
2425

2526
# SECURITY WARNING: don't run with debug turned on in production!
26-
DEBUG = True
27+
DEBUG = str(os.environ.get('DEBUG')) == "1" # 1 == True
2728

2829
ALLOWED_HOSTS = []
29-
30+
if not DEBUG:
31+
ALLOWED_HOSTS += [os.environ.get('ALLOWED_HOST')]
3032

3133
# Application definition
3234
# python manage.py makemigrations

0 commit comments

Comments
 (0)