Ticket #11642: 11642-default-namespace-r11413.diff

File 11642-default-namespace-r11413.diff, 1.5 KB (added by mrmachine, 6 years ago)

Get default app_name from urlconf module.

  • django/conf/urls/defaults.py

     
    11from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
    22from django.core.exceptions import ImproperlyConfigured
     3from django.utils.importlib import import_module
    34
    45__all__ = ['handler404', 'handler500', 'include', 'patterns', 'url']
    56
     
    89
    910def include(arg, namespace=None, app_name=None):
    1011    if isinstance(arg, tuple):
    11         # callable returning a namespace hint
    12         if namespace:
    13             raise ImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')
    14         urlconf_module, app_name, namespace = arg
     12        urlconf_module = arg[0]
     13        app_name = app_name or arg[1]
     14        namespace = namespace or arg[2] or app_name
    1515    else:
    16         # No namespace hint - use manually provided namespace
    17         urlconf_module = arg
     16        if isinstance(arg, basestring):
     17            urlconf_module = import_module(arg)
     18        else:
     19            urlconf_module = arg
     20        # Get the default application namespace, specified in the app's urlconf.
     21        app_name = app_name or getattr(urlconf_module, 'app_name', None)
     22        # Use the app name as the default instance namespace.
     23        namespace = namespace or app_name
    1824    return (urlconf_module, app_name, namespace)
    1925
    2026def patterns(prefix, *args):
Back to Top