Skip to content

Instantly share code, notes, and snippets.

@alsonkemp
Created May 30, 2012 16:55
Show Gist options
  • Save alsonkemp/2837604 to your computer and use it in GitHub Desktop.
Save alsonkemp/2837604 to your computer and use it in GitHub Desktop.
Heroku settings overrides
# 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