Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 17, 2020 05:29
Show Gist options
  • Save velotiotech/3904f14982ce492748da0ba4d2bda161 to your computer and use it in GitHub Desktop.
Save velotiotech/3904f14982ce492748da0ba4d2bda161 to your computer and use it in GitHub Desktop.
Velotio - HashiCorp Consul Part 2 - Using python-consul to consume Consul's KV store to configure Django Web Application
# Set DEBUG flag using Consul KV store
index, data = consul_client.kv.get('web/debug')
DEBUG = data.get('Value', True)
# Set ALLOWED_HOSTS dynamically using Consul KV store
ALLOWED_HOSTS = []
index, hosts = consul_client.kv.get('web/allowed_hosts')
ALLOWED_HOSTS.append(hosts.get('Value'))
# Set INSTALLED_APPS dynamically using Consul KV store
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
index, apps = consul_client.kv.get('web/installed_apps')
INSTALLED_APPS += (bytes(apps.get('Value')).decode('utf-8'),)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment