Skip to content

Instantly share code, notes, and snippets.

@pydanny
Last active January 27, 2025 21:33
Show Gist options
  • Save pydanny/6094883 to your computer and use it in GitHub Desktop.
Save pydanny/6094883 to your computer and use it in GitHub Desktop.
# settings/base.py
import os
# Normally you should not import ANYTHING from Django directly
# into your settings, but ImproperlyConfigured is an exception.
from django.core.exceptions import ImproperlyConfigured
def get_env_variable(var_name):
""" Get the environment variable or return exception """
try:
return os.environ[var_name]
except KeyError:
error_msg = "Set the %s environment variable" % var_name
raise ImproperlyConfigured(error_msg)
@ck9sky
Copy link

ck9sky commented Sep 7, 2020

Thank you, this was very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment