diff --git a/django/conf/urls/__init__.py b/django/conf/urls/__init__.py
index 04fb1df..e88c8b6 100644
a
|
b
|
from django.core.exceptions import ImproperlyConfigured
|
4 | 4 | from django.utils.importlib import import_module |
5 | 5 | from django.utils import six |
6 | 6 | |
| 7 | import imp |
| 8 | |
7 | 9 | |
8 | 10 | __all__ = ['handler403', 'handler404', 'handler500', 'include', 'patterns', 'url'] |
9 | 11 | |
… |
… |
def include(arg, namespace=None, app_name=None):
|
22 | 24 | urlconf_module = arg |
23 | 25 | |
24 | 26 | if isinstance(urlconf_module, six.string_types): |
25 | | urlconf_module = import_module(urlconf_module) |
| 27 | # Attempt to search the namespace packages for all URL modules and append the urlpatterns to the last module found |
| 28 | if namespace: |
| 29 | try: |
| 30 | ns_module = import_module(namespace) |
| 31 | package_list = ns_module.__path__ |
| 32 | |
| 33 | urlpatterns = [] |
| 34 | |
| 35 | for path in package_list: |
| 36 | # Search the path for the module name, unpack the find_module tuple and load said module |
| 37 | tmp_module = imp.load_module(arg, *imp.find_module(arg, [path])) |
| 38 | urlconf_module = tmp_module |
| 39 | urlpatterns += tmp_module.urlpatterns |
| 40 | |
| 41 | urlconf_module.urlpatterns = urlpatterns |
| 42 | except Exception as ex: |
| 43 | raise ImproperlyConfigured('Cannot import namespace for a dynamic url configuration: %s' % (ex)) |
| 44 | else: |
| 45 | urlconf_module = import_module(urlconf_module) |
| 46 | |
26 | 47 | patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module) |
27 | 48 | |
28 | 49 | # Make sure we can iterate through the patterns (without this, some |