Get Django Allowed_hosts Env. Variable Formated Right In Settings.py
I'm facing the following issue. My .env files contains a line like: export SERVERNAMES='localhost domain1 domain2 domain3' <- exactly this kind of format But the variable calle
Solution 1:
Simply split your SERVERNAMES
variable using space as separator instead of comma
ALLOWED_HOSTS = os.environ.get('SERVERNAMES').split(' ')
Solution 2:
The coma is making it a string
env = "localhost domain1 domain2 domain3"
envs = envs.split(',')
print(envs)
['localhost domain1 domain2 domain3']
Instead just split the string with space and python turns it into a list of strings
env = "localhost domain1 domain2 domain3"
envs = env.split() # By default `str.split()` splits upon spacesprint(envs)
['localhost', 'domain1', 'domain2', 'domain3']
Post a Comment for "Get Django Allowed_hosts Env. Variable Formated Right In Settings.py"