0

I am using cookiecutter-django .env design to load different settings depending on environment. Running locally should use "local.py" settings and wunning in aws elatic beanstalk, it should load "dev.py". Both import from "common.py".

Running the server in AES with dev settings works, but collectstatic fails, because it tries importing the local settings instead of dev settings.

How can the EC2 instance run collectstatic and load the (appropriate) dev.py settings?

pedrovgp
  • 767
  • 9
  • 23

1 Answers1

2

OK, found it. The manage.py file looked like this

if __name__ == '__main__':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local')

forcing all commands to run with local settings, instead of loading from the .env file.

I have changet it to

import environ

ROOT_DIR = environ.Path(__file__) - 1

env = environ.Env()
env.read_env(ROOT_DIR.file('config/settings/.env'))

if __name__ == '__main__':
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', env('DJANGO_SETTINGS_MODULE', default='config.settings.local'))

Which allows manage.py commands to run using whatever settings I have actually specified.

pedrovgp
  • 767
  • 9
  • 23