Skip to content

Instantly share code, notes, and snippets.

@pranavcode
Created April 1, 2019 14:55
Show Gist options
  • Save pranavcode/5b607f86a84a838264263db317c42548 to your computer and use it in GitHub Desktop.
Save pranavcode/5b607f86a84a838264263db317c42548 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