def get_setting_with_envfallback(setting, default=None, typecast=None):
    """
    Get the given setting and fall back to the default of not found in
    ``django.conf.settings`` or ``os.environ``.

    :param settings: The setting as a string.
    :param default: The fallback if ``setting`` is not found.
    :param typecast:
        A function that converts the given value from string to another type.
        E.g.: Use ``typecast=int`` to convert the value to int before returning.
    """
    try:
        from django.conf import settings
    except ImportError:
        return default
    else:
        fallback = getattr(settings, setting, default)
        value = os.environ.get(setting, fallback)
        if typecast:
            value = typecast(value)
        return value
Get the given setting and fall back to the default of not found in
    ``django.conf.settings`` or ``os.environ``.

    :param settings: The setting as a string.
    :param default: The fallback if ``setting`` is not found.
    :param typecast:
        A function that converts the given value from string to another type.
        E.g.: Use ``typecast=int`` to convert the value to int before returning.