| 189 | |
| 190 | == Development/Machine Dependant Settings Configuration == |
| 191 | I personally use this solution. |
| 192 | |
| 193 | /path/to/project/settings.py |
| 194 | {{{ |
| 195 | #!python |
| 196 | # Django project settings loader |
| 197 | import os |
| 198 | ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
| 199 | |
| 200 | # You can key the configurations off of anything - I use project path. |
| 201 | configs = { |
| 202 | '/path/to/user1/dev/project': 'user1', |
| 203 | '/path/to/user2/dev/project': 'user2', |
| 204 | '/path/to/qa/project': 'qa', |
| 205 | '/path/to/prod/project': 'prod', |
| 206 | } |
| 207 | |
| 208 | # Import the configuration settings file - REPLACE projectname with your project |
| 209 | config_module = __import__('config.%s' % configs[ROOT_PATH], globals(), locals(), 'projectname') |
| 210 | |
| 211 | # Load the config settings properties into the local scope. |
| 212 | for setting in dir(config_module): |
| 213 | if setting == setting.upper(): |
| 214 | locals()[setting] = getattr(config_module, setting) |
| 215 | }}} |
| 216 | |
| 217 | This settings loader will import the appropriate settings module. I store my settings files in a '''config''' directory in the root of the project. |
| 218 | |
| 219 | /path/to/project/config/prod.py |
| 220 | {{{ |
| 221 | #!python |
| 222 | |
| 223 | DEBUG = False |
| 224 | TEMPLATE_DEBUG = DEBUG |
| 225 | |
| 226 | # don't want emails while developing |
| 227 | ADMINS = () |
| 228 | MANAGERS = ADMINS |
| 229 | |
| 230 | DATABASE_ENGINE = 'mysql' |
| 231 | DATABASE_NAME = 'mydbname' |
| 232 | DATABASE_USER = 'mydbuser' |
| 233 | DATABASE_PASSWORD = 'mydbpassword' |
| 234 | DATABASE_HOST = 'localhost' |
| 235 | DATABASE_PORT = '' |
| 236 | |
| 237 | SECRET_KEY = 'random-string-of-ascii' |
| 238 | |
| 239 | # More production settings |
| 240 | }}} |
| 241 | |
| 242 | /path/to/project/config/user1.py |
| 243 | {{{ |
| 244 | #!python |
| 245 | # Load the production settings that we will overwrite as needed in our user1 settings file. |
| 246 | from projectname.config.prod import * |
| 247 | |
| 248 | DEBUG = True |
| 249 | |
| 250 | DATABASE_NAME = 'devdbname' |
| 251 | |
| 252 | # More development/maching specific settings |
| 253 | }}} |