Login

Dev/staging/prod environment settings seperation

Author:
sleepycal
Posted:
February 6, 2011
Language:
Python
Version:
1.2
Score:
0 (after 2 ratings)

Read code for info

 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. Template tag - list punctuation for a list of items by shapiromatron 3 months ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 1 week ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 10 months, 3 weeks ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.