Skip to content

Commit 4ce62e9

Browse files
LOCAL_HOST has been made optional
README.md mentioned that LOCAL_HOST was optional but it actually was not. Added conditional statements to make it optional. Changed position of PROJECT_ROOT to make sure that all the variables related to static files are found one after the other. Moved an import statement from the bottom to the top to keep all imports in the same place.
1 parent e71de1e commit 4ce62e9

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tutorialdb/settings.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import dj_database_url
23

34
from dotenv import load_dotenv
45
load_dotenv()
@@ -8,15 +9,22 @@
89

910
SECRET_KEY = os.environ['SECRET_KEY']
1011

12+
try:
13+
LOCAL_HOST = os.environ['LOCAL_HOST'] # your local IP to test the site on your network
14+
except:
15+
LOCAL_HOST = None
16+
1117
DEBUG = True
1218

1319
ALLOWED_HOSTS = [
1420
'127.0.0.1',
15-
os.environ['LOCAL_HOST'], # your local IP to test the site on your network,
1621
'tutorialdb.pythonanywhere.com',
17-
'tutorialdb-app.herokuapp.com'
22+
'tutorialdb-app.herokuapp.com',
1823
]
1924

25+
if LOCAL_HOST:
26+
ALLOWED_HOSTS.append(LOCAL_HOST)
27+
2028
# Application definition
2129

2230
INSTALLED_APPS = [
@@ -118,8 +126,10 @@
118126

119127
USE_TZ = True
120128

121-
STATIC_URL = '/static/'
122129
PROJECT_ROOT = os.path.join(os.path.abspath(__file__))
130+
131+
# Location of all static files
132+
STATIC_URL = '/static/'
123133
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
124134

125135
# Extra lookup directories for collectstatic to find static files
@@ -129,6 +139,5 @@
129139

130140
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
131141

132-
import dj_database_url
133142
prod_db = dj_database_url.config(conn_max_age=500)
134143
DATABASES['default'].update(prod_db)

0 commit comments

Comments
 (0)