Use import_module from standard library if exists

Django 1.8+ drops `django.utils.importlib`. I imagine because that is because an older version of Python (either 2.5 and/or 2.6) is being dropped. I haven't checked older versions but `importlib` exists in Python 2.7.
This commit is contained in:
Patrick Altman 2015-02-15 05:01:03 -06:00
parent de23f52139
commit 4848baf76e
1 changed files with 4 additions and 1 deletions

View File

@ -2,7 +2,10 @@ import sys
def import_attribute(import_path, exception_handler=None):
from django.utils.importlib import import_module
try:
from importlib import import_module
except ImportError:
from django.utils.importlib import import_module
module_name, object_name = import_path.rsplit('.', 1)
try:
module = import_module(module_name)