Home / Function/ url_for() — flask Function Reference

url_for() — flask Function Reference

Architecture documentation for the url_for() function in helpers.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  7a5f6a6e_f5af_ab6f_cfee_01851e53dff5["url_for()"]
  881f9803_28d6_7d77_c8d7_1098b41ccf84["helpers.py"]
  7a5f6a6e_f5af_ab6f_cfee_01851e53dff5 -->|defined in| 881f9803_28d6_7d77_c8d7_1098b41ccf84
  d79553e1_9435_9b37_b132_99c938d6f250["url_for()"]
  d79553e1_9435_9b37_b132_99c938d6f250 -->|calls| 7a5f6a6e_f5af_ab6f_cfee_01851e53dff5
  style 7a5f6a6e_f5af_ab6f_cfee_01851e53dff5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/helpers.py lines 187–238

def url_for(
    endpoint: str,
    *,
    _anchor: str | None = None,
    _method: str | None = None,
    _scheme: str | None = None,
    _external: bool | None = None,
    **values: t.Any,
) -> str:
    """Generate a URL to the given endpoint with the given values.

    This requires an active request or application context, and calls
    :meth:`current_app.url_for() <flask.Flask.url_for>`. See that method
    for full documentation.

    :param endpoint: The endpoint name associated with the URL to
        generate. If this starts with a ``.``, the current blueprint
        name (if any) will be used.
    :param _anchor: If given, append this as ``#anchor`` to the URL.
    :param _method: If given, generate the URL associated with this
        method for the endpoint.
    :param _scheme: If given, the URL will have this scheme if it is
        external.
    :param _external: If given, prefer the URL to be internal (False) or
        require it to be external (True). External URLs include the
        scheme and domain. When not in an active request, URLs are
        external by default.
    :param values: Values to use for the variable parts of the URL rule.
        Unknown keys are appended as query string arguments, like
        ``?a=b&c=d``.

    .. versionchanged:: 2.2
        Calls ``current_app.url_for``, allowing an app to override the
        behavior.

    .. versionchanged:: 0.10
       The ``_scheme`` parameter was added.

    .. versionchanged:: 0.9
       The ``_anchor`` and ``_method`` parameters were added.

    .. versionchanged:: 0.9
       Calls ``app.handle_url_build_error`` on build errors.
    """
    return current_app.url_for(
        endpoint,
        _anchor=_anchor,
        _method=_method,
        _scheme=_scheme,
        _external=_external,
        **values,
    )

Subdomains

Called By

Frequently Asked Questions

What does url_for() do?
url_for() is a function in the flask codebase, defined in src/flask/helpers.py.
Where is url_for() defined?
url_for() is defined in src/flask/helpers.py at line 187.
What calls url_for()?
url_for() is called by 1 function(s): url_for.

Analyze Your Own Codebase

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

Try Supermodel Free