# -*- coding: utf-8 -*-

import django
from django.conf import settings
from django.utils.importlib import import_module
from django.utils.module_loading import module_has_submodule


def autodiscover():
    """Auto-discover INSTALLED_APPS mails.py modules."""

    for app in settings.INSTALLED_APPS:
        module = '%s.mails' % app  # Attempt to import the app's 'mails' module
        try:
            import_module(module)
        except:
            # Decide whether to bubble up this error. If the app just
            # doesn't have a mails module, we can ignore the error
            # attempting to import it, otherwise we want it to bubble up.
            app_module = import_module(app)
            if module_has_submodule(app_module, 'mails'):
                raise


# If we're using Django >= 1.7, use the new app-loading mecanism which is way
# better.
if django.VERSION < (1, 7):
    autodiscover()

# -*- coding: utf-8 -*-

import django
from django.conf import settings
from django.utils.module_loading import module_has_submodule

try:
    from importlib import import_module
except ImportError:
    # Compatibility for python-2.6
    from django.utils.importlib import import_module


def autodiscover():
    """Auto-discover INSTALLED_APPS mails.py modules."""

    for app in settings.INSTALLED_APPS:
        module = '%s.mails' % app  # Attempt to import the app's 'mails' module
        try:
            import_module(module)
        except:
            # Decide whether to bubble up this error. If the app just
            # doesn't have a mails module, we can ignore the error
            # attempting to import it, otherwise we want it to bubble up.
            app_module = import_module(app)
            if module_has_submodule(app_module, 'mails'):
                raise


# If we're using Django >= 1.7, use the new app-loading mecanism which is way
# better.
if django.VERSION < (1, 7):
    autodiscover()

Use standard library instead of django.utils.importlib
Use standard library instead of django.utils.importlib

> django.utils.importlib is a compatibility library for when Python 2.6 was
> still supported. It has been obsolete since Django 1.7, which dropped support
> for Python 2.6, and is removed in 1.9 per the deprecation cycle.
> Use Python's import_module function instead
> — [1]

References:
[1] http://stackoverflow.com/a/32763639
[2] https://docs.djangoproject.com/en/1.9/internals/deprecation/#deprecation-removed-in-1-9
