Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a settings file other than settings.py in Django

Tags:

django

I want to use a different settings file in django -- specifically settings_prod -- yet whenever I try to do a syncdb with --settings=settings_prod, it complains:

python2.6 manage.py syncdb  --settings=settings_prod
Error: Can't find the file 'settings.py' in the directory containing 'manage.py'. It appears you've customized things.
You'll have to run django-admin.py, passing it your settings module.
(If the file settings.py does indeed exist, it's causing an ImportError somehow.)

I've also tried setting the environment variable DJANGO_SETTINGS_MODULE=settings_prod to no end.

Edit: I have also set the environment variable in my wsgi file, also to no end:

import os
import sys

from django.core.handlers.wsgi import WSGIHandler

os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings_prod'
application = WSGIHandler()

Suggestions?

like image 986
Brian D Avatar asked Mar 29 '11 00:03

Brian D


People also ask

What is the use of settings py in Django?

Insights about settings.py file. A Django settings file contains all the configuration of your Django Project. In this article the important points of settings.py file of Django will be discussed. A settings file is just a Python module with module-level variables.

Where is the Django settings file?

A Django settings file doesn't have to define any settings if it doesn't need to. Each setting has a sensible default value. These defaults live in the module django/conf/global_settings.py .


1 Answers

Try creating a settings module.

  1. Make a settings folder in the same directory as manage.py.
  2. Put your different settings files in that folder (e.g. base.py and prod.py).
  3. Make __init__.py and import whatever settings you want to use as your default. For example, your __init__.py file might look like this:

    from base import *
    
  4. Run your project and override the settings:

    $ python2.6 manage.py syncdb --settings=settings.prod
    
like image 80
Elliot Cameron Avatar answered Oct 14 '22 10:10

Elliot Cameron