Skip to content

Instantly share code, notes, and snippets.

Last active Oct 17, 2021
What would you like to do?
Starlette Jinja2Templates add relative URL (url_path_for)
#Add to class Jinja2Templates:
def url_path_for(context: dict, name: str, **path_params: typing.Any) -> str:
request = context["request"]
router = request.scope["router"]
return router.url_path_for(name, **path_params)
env.globals["url_path_for"] = url_path_for
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment