python url setting include function

What does include actually do in the URL settings?

You can use include () to retrieve your PATH setting, but what are you actually doing?

(reference) mysite/urls.py

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('polls/', include('polls.urls')),
    path('admin/', admin.site.urls),
]

The original text in the actual function

def include(arg, namespace=None):
    app_name = None
    if isinstance(arg, tuple):
        # Callable returning a namespace hint.
        try:
            urlconf_module, app_name = arg
        except ValueError:
            if namespace:
                raise ImproperlyConfigured(
                    'Cannot override the namespace for a dynamic module that '
                    'provides a namespace.'
                )
            raise ImproperlyConfigured(
                'Passing a %d-tuple to include() is not supported. Pass a '
                '2-tuple containing the list of patterns and app_name, and '
                'provide the namespace argument to include() instead.' % len(arg)
            )
    else:
        # No namespace hint - use manually provided namespace.
        urlconf_module = arg

    if isinstance(urlconf_module, str):
        urlconf_module = import_module(urlconf_module)
    patterns = getattr(urlconf_module, 'urlpatterns', urlconf_module)
    app_name = getattr(urlconf_module, 'app_name', app_name)
    if namespace and not app_name:
        raise ImproperlyConfigured(
            'Specifying a namespace in include() without providing an app_name '
            'is not supported. Set the app_name attribute in the included '
            'module, or pass a 2-tuple containing the list of patterns and '
            'app_name instead.',
        )
    namespace = namespace or app_name
    # Make sure the patterns can be iterated through (without this, some
    # testcases will break).
    if isinstance(patterns, (list, tuple)):
        for url_pattern in patterns:
            pattern = getattr(url_pattern, 'pattern', None)
            if isinstance(pattern, LocalePrefixPattern):
                raise ImproperlyConfigured(
                    'Using i18n_patterns in an included URLconf is not allowed.'
                )
    return (urlconf_module, app_name, namespace)

Recommended Posts

python url setting include function
python function ①
[Python] function
python function ②
python enumerate function
Python> function> Closure
[Python] Generator function
Python> function> Inner function
Python function decorator
About function arguments (python)
Function execution time (Python)
Python function argument summary
Python print function (sequel)
Python: About function arguments
URL shortening with Python
Time floor function (Python)
python Environmentally-friendly Japanese setting
Create a function in Python
Use callback function in Python
Parameter setting by python configparser
[python] Value of function object (?)
ntile (decile) function in python
[Python] Etymology of python function names
About python beginner's memorandum function
About the enumerate function (python)
Python #function 2 for super beginners
Nonlinear function modeling in Python
Draw implicit function in python
Python higher-order function (decorator) sample
Immediate function in python (lie)
Relative url handling in python
[Python] What is a zip function?
Call a Python function from p5.js.
[python] Callback function (pass function as argument)
Implement R's power.prop.test function in python
Function argument type definition in python
Included notation in Python function arguments
[Automation with python! ] Part 1: Setting file
Write AWS Lambda function in Python
Measure function execution time in Python
[Python] Make the function a lambda function
Vim + Python development environment setting memo
Python #len function for super beginners
Function synthesis and application in Python
Basic Python operation 2nd: Function (argument)
How to use python zip function
[Python] Difference between function and method
[Python] Function arguments * (star) and ** (double star)
[OpenCV; Python] Summary of findcontours function