Created
December 1, 2022 18:03
-
-
Save agamm/d5bcdb24249884e714ff1329291864dc to your computer and use it in GitHub Desktop.
Django settings for postgres from URI
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
import urllib | |
# ... | |
DB_URL = config('DATABASE_URL') # Get from your config | |
db_props = urllib.parse.urlparse(DB_URL) | |
db_name = db_props.path | |
db_user = db_props.username | |
db_password = db_props.password | |
db_host = db_props.hostname | |
db_port = db_props.port | |
db_vars = { | |
'ENGINE': config('DATABASE_ENGINE'), | |
'NAME': db_name, | |
'USER': db_user, | |
'PASSWORD': db_password, | |
'HOST': db_host, | |
'PORT': db_port | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment