Reputation: 558
In Django, Because when in development and production mode, the settings.py file has to be so much different
For example
DEBUG = true
...
ALLOWED_HOSTS = []
...
EMAIL_PAGE_DOMAIN = 'http://127.0.0.1:8000'
DEBUG = false
...
ALLOWED_HOSTS = ['example.com']
...
EMAIL_PAGE_DOMAIN = 'https://example.com'
I don't know if there is a condition to check if the app is in development mode or production mode so that I don't hard-code it. The code should change automatically based on its mode. I imagine something like this
if in_Development_Mode() == true:
#code for devopmenet
else:
#code for production
Upvotes: 3
Views: 1684
Reputation: 1370
Another way to validate this using the os.getcwd()
is to check for the production application folder.
if os.getcwd() == '/app':
DEBUG = False # Set to false when in production
else:
DEBUG = True # Set to true when not in production
Can use this for future reference as it can come in handy.
Upvotes: 0
Reputation: 558
You can use os.getcwd()
If the current working directory is not the local directory then the website is in production
if 'C:\\Users\\UserName' in os.getcwd():
DEBUG = True else:
DEBUG = False
Upvotes: 0
Reputation: 324
Yes there is:
from django.conf import settings
if settings.DEBUG==True:
#code for development
else:
#code for production
https://docs.djangoproject.com/en/3.1/topics/settings/#using-settings-in-python-code
Upvotes: 3