<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_setting(key, **kwargs):
 """Gets a settings key or raises an improperly configured error. :param key: the settings key to get. :param default: the default value to return if no value is found """

    has_default = 'default' in kwargs
    default_val = kwargs.get('default')

    try:
        if has_default:
            return getattr(settings, key, default_val)
        else:
            return getattr(settings, key)
    except Exception as e:
        raise ImproperlyConfigured(
            _('"{0}" setting has not been properly set. {1}').format(key, e)
        )