Created
May 30, 2012 16:55
-
-
Save DavidYKay/2837599 to your computer and use it in GitHub Desktop.
Solution to removal of Heroku DB Injection
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
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