Generate a URL to the given endpoint with the given values. This is called by :func:`flask.url_for`, and can be called directly as well. An *endpoint* is the name of a URL rule, usually added with :meth:`@app.route() <route>`, and usually the same name as the
(
self,
/,
endpoint: str,
*,
_anchor: str | None = None,
_method: str | None = None,
_scheme: str | None = None,
_external: bool | None = None,
**values: t.Any,
)
| 1001 | return asgiref_async_to_sync(func) |
| 1002 | |
| 1003 | def url_for( |
| 1004 | self, |
| 1005 | /, |
| 1006 | endpoint: str, |
| 1007 | *, |
| 1008 | _anchor: str | None = None, |
| 1009 | _method: str | None = None, |
| 1010 | _scheme: str | None = None, |
| 1011 | _external: bool | None = None, |
| 1012 | **values: t.Any, |
| 1013 | ) -> str: |
| 1014 | class="st">"""Generate a URL to the given endpoint with the given values. |
| 1015 | |
| 1016 | This is called by :func:`flask.url_for`, and can be called |
| 1017 | directly as well. |
| 1018 | |
| 1019 | An *endpoint* is the name of a URL rule, usually added with |
| 1020 | :meth:`@app.route() <route>`, and usually the same name as the |
| 1021 | view function. A route defined in a :class:`~flask.Blueprint` |
| 1022 | will prepend the blueprint&class="cm">#x27;s name separated by a ``.`` to the |
| 1023 | endpoint. |
| 1024 | |
| 1025 | In some cases, such as email messages, you want URLs to include |
| 1026 | the scheme and domain, like ``https://example.com/hello``. When |
| 1027 | not in an active request, URLs will be external by default, but |
| 1028 | this requires setting :data:`SERVER_NAME` so Flask knows what |
| 1029 | domain to use. :data:`APPLICATION_ROOT` and |
| 1030 | :data:`PREFERRED_URL_SCHEME` should also be configured as |
| 1031 | needed. This config is only used when not in an active request. |
| 1032 | |
| 1033 | Functions can be decorated with :meth:`url_defaults` to modify |
| 1034 | keyword arguments before the URL is built. |
| 1035 | |
| 1036 | If building fails for some reason, such as an unknown endpoint |
| 1037 | or incorrect values, the app&class="cm">#x27;s :meth:`handle_url_build_error` |
| 1038 | method is called. If that returns a string, that is returned, |
| 1039 | otherwise a :exc:`~werkzeug.routing.BuildError` is raised. |
| 1040 | |
| 1041 | :param endpoint: The endpoint name associated with the URL to |
| 1042 | generate. If this starts with a ``.``, the current blueprint |
| 1043 | name (if any) will be used. |
| 1044 | :param _anchor: If given, append this as ``class="cm">#anchor`` to the URL. |
| 1045 | :param _method: If given, generate the URL associated with this |
| 1046 | method for the endpoint. |
| 1047 | :param _scheme: If given, the URL will have this scheme if it |
| 1048 | is external. |
| 1049 | :param _external: If given, prefer the URL to be internal |
| 1050 | (False) or require it to be external (True). External URLs |
| 1051 | include the scheme and domain. When not in an active |
| 1052 | request, URLs are external by default. |
| 1053 | :param values: Values to use for the variable parts of the URL |
| 1054 | rule. Unknown keys are appended as query string arguments, |
| 1055 | like ``?a=b&c=d``. |
| 1056 | |
| 1057 | .. versionadded:: 2.2 |
| 1058 | Moved from ``flask.url_for``, which calls this method. |
| 1059 | class="st">""" |
| 1060 | req_ctx = _cv_request.get(None) |