def get_class(import_path=None):
"""
Largely based on django.core.files.storage's get_storage_class
"""
from django.core.exceptions import ImproperlyConfigured
if import_path is None:
raise ImproperlyConfigured('No class path specified.')
try:
dot = import_path.rindex('.')
except ValueError:
raise ImproperlyConfigured("%s isn't a module." % import_path)
module, classname = import_path[:dot], import_path[dot+1:]
try:
mod = import_module(module)
except ImportError as e:
raise ImproperlyConfigured('Error importing module %s: "%s"' % (module, e))
try:
return getattr(mod, classname)
except AttributeError:
raise ImproperlyConfigured('Module "%s" does not define a "%s" class.' % (module, classname))
评论列表
文章目录