Created
May 30, 2012 16:55
-
-
Save alsonkemp/2837604 to your computer and use it in GitHub Desktop.
Heroku settings overrides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# the usual settings.py above here | |
import urlparse | |
# Register database schemes in URLs. | |
urlparse.uses_netloc.append('postgres') | |
# Heroku overrides | |
try: | |
# Check to make sure DATABASES is set in settings.py file. | |
# If not default to {} | |
if 'DATABASES' not in locals(): | |
DATABASES = {} | |
if 'DATABASE_URL' in os.environ: | |
url = urlparse.urlparse(os.environ['DATABASE_URL']) | |
# Ensure default database exists. | |
DATABASES['default'] = DATABASES.get('default', {}) | |
# Update with environment configuration. | |
DATABASES['default'].update({ | |
'NAME': url.path[1:], | |
'USER': url.username, | |
'PASSWORD': url.password, | |
'HOST': url.hostname, | |
'PORT': url.port, | |
}) | |
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2' | |
if 'CACHES' not in locals(): | |
CACHES = {} | |
if 'MEMCACHE_USERNAME' in os.environ: | |
CACHES = { | |
'default': { | |
'BACKEND' : 'johnny.backends.memcached.MemcachedCache', | |
'LOCATION': '%s:11211' % (os.environ['MEMCACHE_SERVERS']), | |
'username': os.environ.get('MEMCACHE_USERNAME'), | |
'password': os.environ.get('MEMCACHE_PASSWORD'), | |
'JOHNNY_CACHE': True | |
} | |
} | |
except Exception as e: | |
print " *** Caught exception in Heroku settings.py overrides: %s" % e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment