12đź‘Ť
âś…
import socket
socket.gethostbyname(socket.gethostname())
However, I’d recommend against this and instead maintain multiple settings file for each environment you’re working with.
settings/__init__.py
settings/qa.py
settings/production.py
__init__.py
has all of your defaults. At the top of qa.py
, and any other settings file, the first line has:
from settings import *
followed by any overrides needed for that particular environment.
👤brianz
3đź‘Ť
One method some shops use is to have an environment variable set on each machine. Maybe called “environment”. In POSIX systems you can do something like ENVIRONMENT=production
in the user’s .profile file (this will be slightly different for each shell and OS). Then in settings.py
you can do something like this:
import os
if os.environ['ENVIRONMENT'] == 'production':
# Production
DATABASE_ENGINE = 'mysql'
DATABASE_NAME = ....
else:
# Development
👤Matt Williamson
- [Django]-How to import django models in scrapy pipelines.py file
- [Django]-How do I send XML POST data from an iOS app to a Django app?
- [Django]-Is it possible to get an interactive django shell using the test database?
- [Django]-Django occasionally throwing a NoReverseMatch
Source:stackexchange.com