What is the recommended way of handling settings for local development and the production server? Some of them (like constants, etc) can be changed/accessed in both, but s
I had my settings split as follows
settings/
|
|- base.py
|- dev.py
|- prod.py
We have 3 environments
Now obviously staging and production should have the maximum possible similar environment. So we kept prod.py
for both.
But there was a case where I had to identify running server is a production server. @T. Stone 's answer helped me write check as follows.
from socket import gethostname, gethostbyname
PROD_HOSTS = ["webserver1", "webserver2"]
DEBUG = False
ALLOWED_HOSTS = [gethostname(), gethostbyname(gethostname()),]
if any(host in PROD_HOSTS for host in ALLOWED_HOSTS):
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True