Dev/staging/prod environment settings seperation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""

Using the below, you can then issue commands like the following from the shell

DJANGO_ENVIRONMENT=dev /path/to/manage.py shell
DJANGO_ENVIRONMENT=dev /path/to/manage.py runfcgi
etc etc

You can also use this very nicely with supervisord and uwsgi.

ALSO, you can have individual settings based on the local server hostname:

import socket
if socket.gethostname() == 'sws01.internal':
    pass
else:
    pass

etc etc
"""
#settings.py

# Add this to the top of your settings.py
if not os.environ.has_key('DJANGO_ENVIRONMENT'):
    raise Exception, "You must provide environ DJANGO_ENVIRONMENT (dev/staging/prod)"
if not os.environ.get('DJANGO_ENVIRONMENT') in ('dev', 'staging', 'prod'):
    raise Exception, "Invalid environment specified, DJANGO_ENVIRONMENT must be (dev/staging/prod)"

if os.environ['DJANGO_ENVIRONMENT']=='dev':
    # Enable debug mode
    DEBUG = True
    TEMPLATE_DEBUG = DEBUG
    SHOW_DEBUG_TOOLBAR = True

    # Database
    DATABASE_NAME = ''
    DATABASE_USER = ''
    DATABASE_PASSWORD = ''
    DATABASE_HOST = ''
    DATABASE_PORT = ''

    # Celery Broker
    BROKER_HOST = "mysql01.internal"
    BROKER_PORT = 5672
    BROKER_USER = "simplicitymedialtd"
    BROKER_PASSWORD = ""
    BROKER_VHOST = "cdn06_dev"

    # Cache settings
    CACHE_BACKEND = 'memcached://hostname:12345/'


if os.environ['DJANGO_ENVIRONMENT']=='staging':
    # Enable debug mode
    DEBUG = True
    TEMPLATE_DEBUG = DEBUG
    SHOW_DEBUG_TOOLBAR = True

    # Database
    DATABASE_NAME = ''
    DATABASE_USER = ''
    DATABASE_PASSWORD = ''
    DATABASE_HOST = ''
    DATABASE_PORT = ''

    # Celery Broker
    BROKER_HOST = "mysql01.internal"
    BROKER_PORT = 5672
    BROKER_USER = "simplicitymedialtd"
    BROKER_PASSWORD = ""
    BROKER_VHOST = "cdn06_dev"

    # Cache settings
    CACHE_BACKEND = 'memcached://hostname:12345/'


if os.environ['DJANGO_ENVIRONMENT']=='prod':
    # Enable debug mode
    DEBUG = False
    TEMPLATE_DEBUG = DEBUG
    SHOW_DEBUG_TOOLBAR = True

    # Database
    DATABASE_NAME = ''
    DATABASE_USER = ''
    DATABASE_PASSWORD = ''
    DATABASE_HOST = ''
    DATABASE_PORT = ''

    # Celery Broker
    BROKER_HOST = "mysql01.internal"
    BROKER_PORT = 5672
    BROKER_USER = "simplicitymedialtd"
    BROKER_PASSWORD = ""
    BROKER_VHOST = "cdn06_dev"

    # Cache settings
    CACHE_BACKEND = 'memcached://hostname:12345/'

More like this

  1. Load a local settings file for dev/test environments by menendez 5 years, 8 months ago
  2. Load local settings by ofalk 4 years, 10 months ago
  3. Debug-only static serving by ludvig.ericson 6 years, 3 months ago
  4. Rails-like environments using Django by ElfSternberg 4 years, 6 months ago
  5. Url overrides and concurrent site versions by henrikv 7 years, 1 month ago

Comments

(Forgotten your password?)