Skip to content

Instantly share code, notes, and snippets.

@velotiotech
Created June 17, 2020 05:29

Revisions

  1. velotiotech created this gist Jun 17, 2020.
    22 changes: 22 additions & 0 deletions django-settings.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # 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'),)