Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django, changing the default location of settings.py or use another file

Tags:

python

django

I am trying to set a new structure for settings.py in my django app. ( Django 1.7b4 - python 3.3.2 )

- manage.py
- mainapp
  -- wsgi.py
  -- urls.py
  -- settings
     --- __init__.py
     --- common.py
     --- development.py
     --- production.py

I have changed manage.py and wsgi.py as

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mainapp.settings.common")

But i got an 'Empty Secret Key Error'. Because django still tries to find settings inside mainapp.settings ( which is default ) and looks inside the empty init.py file...

In my mac os terminal i checked and changed DJANGO_SETTINGS_MODULE environment variable... But nothing changes. Django always search in default location.

like image 696
ratata Avatar asked Oct 25 '25 21:10

ratata


1 Answers

You need to set the DJANGO_SETTINGS_MODULE environment variable for your web server. In the case of apache this takes the form:

SetEnv DJANGO_SETTINGS_MODULE mainapp.settings.common

I've added this in my virtualhost configuration and it works great

If you are using the development server (runserver) you can specify a custom settings module:

python manage.py runserver --settings=mainapp.settings.common
like image 70
hellsgate Avatar answered Oct 27 '25 10:10

hellsgate



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!