1
Look at the order of the settings file:
- first it imports from base: DEBUG is False
- then it imports from local: DEBUG is True
- then it imports from production: at this point, DEBUG is True, so your
if not settings.DEBUG:
block is never entered, and DEBUG is not set to False again.
Thus, DEBUG remains True, as it is set in the local settings file.
I’m not sure what the purpose of your if not settings.DEBUG
check is, but I think if you eliminate that condition, it will work as you expect.
[Edit]
Though the above did answer your question of “Why is that?”, it doesn’t really help meet your needs, so I’d recommend making a modification to your settings file like so:
from .base import *
if os.environ['DJANGO_SERVER_TYPE'] == 'local':
try:
from .local import *
except:
pass
if os.environ['DJANGO_SERVER_TYPE'] == 'production':
try:
from .production import *
except:
pass
0
ultimately this is what worked for me
from .base import *
if os.getenv('_system_name') == 'OSX':
from .local import *
else:
from .production import *
I don’t understand why tutorials make this so complicated. I ran printenv to look at the variables I was creating and try to understand why they weren’t working. I noticed
_system_name=OSX
and thought I could use this because hopefully heroku didn’t have the same name for their server
at the same time in one of my chrome tabs(I had multiple tabs open looking for an answer) I looked at a post on how to use environment variables because this
os.environ['DJANGO_SERVER_TYPE'] == 'production'
kept giving me this error
File "/Users/ray/Desktop/myheroku/practice/src/gettingstarted/settings/__init__.py", line 3, in <module>
if os.environ['DJANGO_SERVER_TYPE'] == 'local':
File "/Users/ray/Desktop/myheroku/practice/bin/../lib/python3.5/os.py", line 683, in __getitem__
raise KeyError(key) from None
KeyError: 'DJANGO_SERVER_TYPE'
so I saw someone using this
os.getenv('TAG')
and figured I could use it like this
os.getenv('_system_name') == 'OSX'
and now my local works as it’s supposed to and my production works as it’s supposed to. I was currently trying to get this to work
from .base import *
try:
from .local import *
except:
pass
try:
from .production import *
except:
pass
which I have been seeking advice on and have been trying to make work for the last 3 days. If my solution isn’t proper please let me know why it isn’t. but as of right now it’s working
- Django + AngularJS: REST-like endpoints without the Django REST framework using plain URLs and views?
- Updating/overwriting HTML data with jQuery?
- Validation Exclude Self From QuerySet