Skip to content

Commit

Permalink
Allow "name" argument on templates url_for() (#2127)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
rosstitmarsh and Kludex committed May 31, 2023
1 parent 22575e6 commit 5898f21
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions starlette/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ def _create_env(
**env_options: typing.Any,
) -> "jinja2.Environment":
@pass_context
def url_for(context: dict, name: str, **path_params: typing.Any) -> URL:
# TODO: Make `__name` a positional-only argument when we drop Python 3.7
# support.
def url_for(context: dict, __name: str, **path_params: typing.Any) -> URL:
request = context["request"]
return request.url_for(name, **path_params)
return request.url_for(__name, **path_params)

loader = jinja2.FileSystemLoader(directory)
env_options.setdefault("loader", loader)
Expand Down

0 comments on commit 5898f21

Please sign in to comment.