[docs]definclude(arg,namespace=None,app_name=None):ifapp_nameandnotnamespace:raiseValueError('Must specify a namespace if specifying app_name.')ifapp_name:warnings.warn('The app_name argument to django.conf.urls.include() is deprecated. ''Set the app_name in the included URLconf instead.',RemovedInDjango20Warning,stacklevel=2)ifisinstance(arg,tuple):# callable returning a namespace hinttry:urlconf_module,app_name=argexceptValueError:ifnamespace:raiseImproperlyConfigured('Cannot override the namespace for a dynamic module that provides a namespace')warnings.warn('Passing a 3-tuple to django.conf.urls.include() is deprecated. ''Pass a 2-tuple containing the list of patterns and app_name, ''and provide the namespace argument to include() instead.',RemovedInDjango20Warning,stacklevel=2)urlconf_module,app_name,namespace=argelse:# No namespace hint - use manually provided namespaceurlconf_module=argifisinstance(urlconf_module,six.string_types):urlconf_module=import_module(urlconf_module)patterns=getattr(urlconf_module,'urlpatterns',urlconf_module)app_name=getattr(urlconf_module,'app_name',app_name)ifnamespaceandnotapp_name:warnings.warn('Specifying a namespace in django.conf.urls.include() without ''providing an app_name is deprecated. Set the app_name attribute ''in the included module, or pass a 2-tuple containing the list of ''patterns and app_name instead.',RemovedInDjango20Warning,stacklevel=2)namespace=namespaceorapp_name# Make sure we can iterate through the patterns (without this, some# testcases will break).ifisinstance(patterns,(list,tuple)):forurl_patterninpatterns:# Test if the LocaleRegexURLResolver is used within the include;# this should throw an error since this is not allowed!ifisinstance(url_pattern,LocaleRegexURLResolver):raiseImproperlyConfigured('Using i18n_patterns in an included URLconf is not allowed.')return(urlconf_module,app_name,namespace)

[docs]defurl(regex,view,kwargs=None,name=None):ifisinstance(view,(list,tuple)):# For include(...) processing.urlconf_module,app_name,namespace=viewreturnRegexURLResolver(regex,urlconf_module,kwargs,app_name=app_name,namespace=namespace)elifcallable(view):returnRegexURLPattern(regex,view,kwargs,name)else:raiseTypeError('view must be a callable or a list/tuple in the case of include().')