Ticket #19556: url_loader_2.diff

File url_loader_2.diff, 1.7 KB (added by hirokiky, 2 years ago)

Fixed indents for the first patch.

  • django/conf/urls/__init__.py

    diff --git a/django/conf/urls/__init__.py b/django/conf/urls/__init__.py
    index 04fb1df..16cbdcb 100644
    a b from django.core.exceptions import ImproperlyConfigured 
    44from django.utils.importlib import import_module
    55from django.utils import six
    66
     7import imp
     8
    79
    810__all__ = ['handler403', 'handler404', 'handler500', 'include', 'patterns', 'url']
    911
    def include(arg, namespace=None, app_name=None): 
    2224        urlconf_module = arg
    2325
    2426    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
    2647    patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
    2748
    2849    # Make sure we can iterate through the patterns (without this, some
Back to Top