Handle AttributeError as well (when the imported module exists but

the specified function/class does not).
This commit is contained in:
Laszlo Marai 2015-06-30 05:49:44 +02:00
parent 5833a1847f
commit f0bced6413

View File

@ -171,7 +171,7 @@ def import_from_string(val, setting_name):
module_path, class_name = '.'.join(parts[:-1]), parts[-1]
module = importlib.import_module(module_path)
return getattr(module, class_name)
except ImportError as e:
except (ImportError, AttributeError) as e:
msg = "Could not import '%s' for API setting '%s'. %s: %s." % (val, setting_name, e.__class__.__name__, e)
raise ImportError(msg)