Skip to content

Commit

Permalink
Merge branch 'master' of github.com:encode/starlette into anyio
Browse files Browse the repository at this point in the history
  • Loading branch information
uSpike committed May 13, 2021
2 parents 3cce6a9 + d26f44b commit cbc2e68
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion starlette/templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

try:
import jinja2

# @contextfunction renamed to @pass_context in Jinja 3.0, to be removed in 3.1
if hasattr(jinja2, "pass_context"):
pass_context = jinja2.pass_context
else: # pragma: nocover
pass_context = jinja2.contextfunction
except ImportError: # pragma: nocover
jinja2 = None # type: ignore

Expand Down Expand Up @@ -53,7 +59,7 @@ def __init__(self, directory: str) -> None:
self.env = self.get_env(directory)

def get_env(self, directory: str) -> "jinja2.Environment":
@jinja2.contextfunction
@pass_context
def url_for(context: dict, name: str, **path_params: typing.Any) -> str:
request = context["request"]
return request.url_for(name, **path_params)
Expand Down

0 comments on commit cbc2e68

Please sign in to comment.