blob: e0c3d52aa9b0e7a0da9c7c10fc7ba26b4beb0971 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
from django.utils import importlib
def load_object(import_path):
"""Util for importing objects from import path.
:param import_path: import path of object to be imported e.g. module.submodule.Class
:type import_path: string
:returns: imported object
:rtype: object
:raises: ValueError, ImportError, AttributeError
"""
if not (isinstance(import_path, basestring) and '.' in import_path):
raise ValueError('There must be at least one dot in import path: "%s"', import_path)
module_name, object_name = import_path.rsplit('.', 1)
module = importlib.import_module(module_name)
return getattr(module, object_name)
|