Last active
June 14, 2022 05:07
-
-
Save bryanchow/d30c0c7021f93b416744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment