using rsplit to get module and classname for imports

This commit is contained in:
David de Sousa 2017-12-27 17:52:47 +01:00
parent 991868a897
commit 6fc5bd149e
No known key found for this signature in database
GPG Key ID: DC2940511A838660

View File

@ -179,8 +179,7 @@ def import_from_string(val, setting_name):
"""
try:
# Nod to tastypie's use of importlib.
parts = val.split('.')
module_path, class_name = '.'.join(parts[:-1]), parts[-1]
module_path, class_name = val.rsplit('.', 1)
module = import_module(module_path)
return getattr(module, class_name)
except (ImportError, AttributeError) as e: