# https://gist.github.com/bryanchow/d30c0c7021f93b416744 from django.conf import settings from django.core.exceptions import ImproperlyConfigured def require_settings(*args): """ Check django.settings for the presence of the specified keys. Accepts settings keys as function args, or as a list of strings. Usage: require_settings('SITE_URL', 'DEFAULT_DOMAIN') require_settings(['SITE_URL', 'DEFAULT_DOMAIN']) """ if len(args) == 1 and not isinstance(args[0], str): args = args[0] for key in args: if not hasattr(settings, key): raise ImproperlyConfigured( "{} not defined in settings".format(key) )