Skip to content

Instantly share code, notes, and snippets.

@bryanchow
Last active June 14, 2022 05:07
Show Gist options
  • Select an option

  • Save bryanchow/d30c0c7021f93b416744 to your computer and use it in GitHub Desktop.

Select an option

Save bryanchow/d30c0c7021f93b416744 to your computer and use it in GitHub Desktop.

Revisions

  1. bryanchow revised this gist Jun 14, 2022. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions require_settings.py
    Original file line number Diff line number Diff line change
    @@ -14,9 +14,11 @@ def require_settings(*args):
    require_settings(['SITE_URL', 'DEFAULT_DOMAIN'])
    """

    if len(args) == 1 and not isinstance(args[0], basestring):
    if len(args) == 1 and not isinstance(args[0], str):
    args = args[0]

    for key in args:
    if not hasattr(settings, key):
    raise ImproperlyConfigured, "%s not defined in settings" % key
    raise ImproperlyConfigured(
    "{} not defined in settings".format(key)
    )
  2. bryanchow revised this gist Feb 15, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion require_settings.py
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    # https://gist.github.com/bryanchow/d30c0c7021f93b416744

    from django.conf import settings
    from django.core.exceptions import ImproperlyConfigured

    @@ -17,4 +19,4 @@ def require_settings(*args):

    for key in args:
    if not hasattr(settings, key):
    raise ImproperlyConfigured, "%s not defined in settings" % key
    raise ImproperlyConfigured, "%s not defined in settings" % key
  3. bryanchow renamed this gist Feb 15, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. bryanchow created this gist Feb 15, 2016.
    20 changes: 20 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    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], basestring):
    args = args[0]

    for key in args:
    if not hasattr(settings, key):
    raise ImproperlyConfigured, "%s not defined in settings" % key