Skip to content

Instantly share code, notes, and snippets.

@DavidYKay
Created May 30, 2012 16:55
Show Gist options
  • Save DavidYKay/2837599 to your computer and use it in GitHub Desktop.
Save DavidYKay/2837599 to your computer and use it in GitHub Desktop.
Solution to removal of Heroku DB Injection
try:
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,
})
if url.scheme == 'postgres':
DATABASES['default']['ENGINE'] = 'django.db.backends.postgresql_psycopg2'
if url.scheme == 'mysql':
DATABASES['default']['ENGINE'] = 'django.db.backends.mysql'
except Exception:
print 'Unexpected error:', sys.exc_info()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment