Question

I have several customized django settings, this is basically my project structure:

MainProject/
  manage.py
  my_project/
    settings/
      base.py
      dev.py
      prod.py

I've created the __init__.py files inside the directories to identify them as packages.
I've exported the DJANGO_SETTINGS_MODULE to point to the chosen settings file.
The manage.py command seems to handle it pretty good, I never had problem with it.

The problem is that no matter what I do the django-admin.py is not able to find any settings file. I've tried several possible solution but nothing seems to work so far.

  1. I've used the --settings=my_project.settings.dev
  2. I've edited and hard-coded the manage.py to let it point to the dev.py file
  3. I've created a settings file either inside the MainProject and my_project directories importing the dev file (that in turn imports the base.py).
  4. I've created a settings file that let Django know which files should it use as settings

This is regarding the point 4:

from django.core.management import setup_environ
try:
    import my_project.settings.dev as settings
except ImportError:
    import sys
    sys.stderr.write("Couldn't find the settings.py module.")
    sys.exit(1)
setup_environ(settings)

Nothing seems to work so far.

====================================

SOLUTION:
I did not find the exact solution but thanks to a comment on the chosen answer I understood that you can basically use manage.py for everything that you could do in django-admin.py, I didn't know that! Since things DO work for me using manage.py I'm fine with it.

Was it helpful?

Solution

What I recommend doing:

Create a normal settings.py file and import one of the others in there. This avoids duplication of settings shared among the three scenarios + it is actually the recommended way of doing it according to the DRY principle.

Typically, you will only have the set the debug parameter, database settings and private keys in the specific settings files. All the other settings should be shared among all scenarios to avoid forgetting to update one and getting hard to debug errors.

OTHER TIPS

Have you tried to import the dev settings inside the __init__.py from your settings module?

settings/_init_.py

from .dev import *

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top