Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing multiple settings.py files [duplicate]

Possible Duplicate:
How to manage local vs production settings in Django?

I have managed to deploy successfully a Django project on Apache's Web Server with mod_wsgi.

I would like some recommendations on how to manage multiple settings.py files. Right now I have one for development and one totally different for production (regarding DB parameters, static content localization, and stuff like that). My settings.py file is versioned (don't know if this is a good practise) and I deploy it with something like:

$ hg archive myproject.tbz2
$ cd /path/of/apache/web/project/location
$ bzip2 -db /home/myself/myproject/myproject.tbz2 | tar -xvf -

It's working OK. But I find myself manipulating multiple settings.py files.

I guess my question is: what are the best practices when deploying DJANGO PROJECTS regarding multiple settings.py file versions?

like image 848
Pablo Santa Cruz Avatar asked Mar 01 '11 20:03

Pablo Santa Cruz


1 Answers

I use a settings module that is not a single file:

settings/
    __init__.py
    _base.py
    _servers.py
    development.py
    production.py
    testing.py

The __init__.py file is simple:

from _servers import get_server_type
exec("from %s import *" % get_server_type())

The _base.py file contains all of the common settings across all server types.

The _servers.py file contains a function get_server_type() that uses socket.gethostname() to determine what type of server the current machine is: it returns development, production or testing.

Then the other files look a bit like (production.py):

DEBUG=False
TEMPLATE_DEBUG=False
from _base import *

In each of these files, I put in the settings that only apply to this server type.

like image 65
Matthew Schinckel Avatar answered Oct 26 '22 23:10

Matthew Schinckel