Skip to content

Instantly share code, notes, and snippets.

@agamm
Created December 1, 2022 18:03
Show Gist options
  • Save agamm/d5bcdb24249884e714ff1329291864dc to your computer and use it in GitHub Desktop.
Save agamm/d5bcdb24249884e714ff1329291864dc to your computer and use it in GitHub Desktop.
Django settings for postgres from URI
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