The solution is to use environment variables.
In celery.py
Instead
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
using
os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{0}'.format(get_env_setting('DJANGO_SETTINGS_MODULE')))
C is get_env_settingdefined as:
from os import environ
from django.core.exceptions import ImproperlyConfigured
def get_env_setting(setting):
""" Get the environment setting or return exception """
try:
return environ[setting]
except KeyError:
error_msg = "Set the %s env variable" % setting
raise ImproperlyConfigured(error_msg)
You can put this in your settings.base.pyexample ..
Then set the environment variable DJANGO_SETTINGS_MODULEfor each environment. For example. Install it in my_project.settings.productiona production environment. This variable can be permanently set by adding the following line to ~ / .bashrc:
export DJANGO_SETTINGS_MODULE=my_project.settings.production
source
share