Home / Function/ add_url_rule() — flask Function Reference

add_url_rule() — flask Function Reference

Architecture documentation for the add_url_rule() function in scaffold.py from the flask codebase.

Entity Profile

Dependency Diagram

graph TD
  878f8299_c5bc_f34c_67ae_8bae8fd95fa0["add_url_rule()"]
  a813bd5c_bf41_d926_8dde_6a113d5e0018["Scaffold"]
  878f8299_c5bc_f34c_67ae_8bae8fd95fa0 -->|defined in| a813bd5c_bf41_d926_8dde_6a113d5e0018
  7889a405_44a8_098c_785b_8fb560b8ae6b["route()"]
  7889a405_44a8_098c_785b_8fb560b8ae6b -->|calls| 878f8299_c5bc_f34c_67ae_8bae8fd95fa0
  22be24c3_a691_fecd_0255_dd39f9f3f245["endpoint()"]
  22be24c3_a691_fecd_0255_dd39f9f3f245 -->|calls| 878f8299_c5bc_f34c_67ae_8bae8fd95fa0
  4a067460_947c_1e17_83f2_27f565351cdb["add_url_rule()"]
  4a067460_947c_1e17_83f2_27f565351cdb -->|calls| 878f8299_c5bc_f34c_67ae_8bae8fd95fa0
  7889a405_44a8_098c_785b_8fb560b8ae6b["route()"]
  878f8299_c5bc_f34c_67ae_8bae8fd95fa0 -->|calls| 7889a405_44a8_098c_785b_8fb560b8ae6b
  22be24c3_a691_fecd_0255_dd39f9f3f245["endpoint()"]
  878f8299_c5bc_f34c_67ae_8bae8fd95fa0 -->|calls| 22be24c3_a691_fecd_0255_dd39f9f3f245
  style 878f8299_c5bc_f34c_67ae_8bae8fd95fa0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/flask/sansio/scaffold.py lines 368–433

    def add_url_rule(
        self,
        rule: str,
        endpoint: str | None = None,
        view_func: ft.RouteCallable | None = None,
        provide_automatic_options: bool | None = None,
        **options: t.Any,
    ) -> None:
        """Register a rule for routing incoming requests and building
        URLs. The :meth:`route` decorator is a shortcut to call this
        with the ``view_func`` argument. These are equivalent:

        .. code-block:: python

            @app.route("/")
            def index():
                ...

        .. code-block:: python

            def index():
                ...

            app.add_url_rule("/", view_func=index)

        See :ref:`url-route-registrations`.

        The endpoint name for the route defaults to the name of the view
        function if the ``endpoint`` parameter isn't passed. An error
        will be raised if a function has already been registered for the
        endpoint.

        The ``methods`` parameter defaults to ``["GET"]``. ``HEAD`` is
        always added automatically, and ``OPTIONS`` is added
        automatically by default.

        ``view_func`` does not necessarily need to be passed, but if the
        rule should participate in routing an endpoint name must be
        associated with a view function at some point with the
        :meth:`endpoint` decorator.

        .. code-block:: python

            app.add_url_rule("/", endpoint="index")

            @app.endpoint("index")
            def index():
                ...

        If ``view_func`` has a ``required_methods`` attribute, those
        methods are added to the passed and automatic methods. If it
        has a ``provide_automatic_methods`` attribute, it is used as the
        default if the parameter is not passed.

        :param rule: The URL rule string.
        :param endpoint: The endpoint name to associate with the rule
            and view function. Used when routing and building URLs.
            Defaults to ``view_func.__name__``.
        :param view_func: The view function to associate with the
            endpoint name.
        :param provide_automatic_options: Add the ``OPTIONS`` method and
            respond to ``OPTIONS`` requests automatically.
        :param options: Extra options passed to the
            :class:`~werkzeug.routing.Rule` object.
        """
        raise NotImplementedError

Subdomains

Frequently Asked Questions

What does add_url_rule() do?
add_url_rule() is a function in the flask codebase, defined in src/flask/sansio/scaffold.py.
Where is add_url_rule() defined?
add_url_rule() is defined in src/flask/sansio/scaffold.py at line 368.
What does add_url_rule() call?
add_url_rule() calls 2 function(s): endpoint, route.
What calls add_url_rule()?
add_url_rule() is called by 3 function(s): add_url_rule, endpoint, route.

Analyze Your Own Codebase

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

Try Supermodel Free