Home / Function/ create_url_adapter() — flask Function Reference

create_url_adapter() — flask Function Reference

Architecture documentation for the create_url_adapter() function in app.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  50282238_729d_4729_21d4_c290921ffa61["create_url_adapter()"]
  9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5["Flask"]
  50282238_729d_4729_21d4_c290921ffa61 -->|defined in| 9f8cc56e_d5c4_e7a8_438a_3124c0dd5de5
  d79553e1_9435_9b37_b132_99c938d6f250["url_for()"]
  d79553e1_9435_9b37_b132_99c938d6f250 -->|calls| 50282238_729d_4729_21d4_c290921ffa61
  31e318e5_adf8_900b_d893_adb4ea07a9b9["__init__()"]
  31e318e5_adf8_900b_d893_adb4ea07a9b9 -->|calls| 50282238_729d_4729_21d4_c290921ffa61
  style 50282238_729d_4729_21d4_c290921ffa61 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/app.py lines 508–559

    def create_url_adapter(self, request: Request | None) -> MapAdapter | None:
        """Creates a URL adapter for the given request. The URL adapter
        is created at a point where the request context is not yet set
        up so the request is passed explicitly.

        .. versionchanged:: 3.1
            If :data:`SERVER_NAME` is set, it does not restrict requests to
            only that domain, for both ``subdomain_matching`` and
            ``host_matching``.

        .. versionchanged:: 1.0
            :data:`SERVER_NAME` no longer implicitly enables subdomain
            matching. Use :attr:`subdomain_matching` instead.

        .. versionchanged:: 0.9
           This can be called outside a request when the URL adapter is created
           for an application context.

        .. versionadded:: 0.6
        """
        if request is not None:
            if (trusted_hosts := self.config["TRUSTED_HOSTS"]) is not None:
                request.trusted_hosts = trusted_hosts

            # Check trusted_hosts here until bind_to_environ does.
            request.host = get_host(request.environ, request.trusted_hosts)  # pyright: ignore
            subdomain = None
            server_name = self.config["SERVER_NAME"]

            if self.url_map.host_matching:
                # Don't pass SERVER_NAME, otherwise it's used and the actual
                # host is ignored, which breaks host matching.
                server_name = None
            elif not self.subdomain_matching:
                # Werkzeug doesn't implement subdomain matching yet. Until then,
                # disable it by forcing the current subdomain to the default, or
                # the empty string.
                subdomain = self.url_map.default_subdomain or ""

            return self.url_map.bind_to_environ(
                request.environ, server_name=server_name, subdomain=subdomain
            )

        # Need at least SERVER_NAME to match/build outside a request.
        if self.config["SERVER_NAME"] is not None:
            return self.url_map.bind(
                self.config["SERVER_NAME"],
                script_name=self.config["APPLICATION_ROOT"],
                url_scheme=self.config["PREFERRED_URL_SCHEME"],
            )

        return None

Subdomains

Defined In

Frequently Asked Questions

What does create_url_adapter() do?
create_url_adapter() is a function in the flask codebase, defined in src/flask/app.py.
Where is create_url_adapter() defined?
create_url_adapter() is defined in src/flask/app.py at line 508.
What calls create_url_adapter()?
create_url_adapter() is called by 2 function(s): __init__, url_for.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free