]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Update the Jinja2Templates() constructor to allow PathLike (#1292)
authorAnthony Shaw <anthony.p.shaw@gmail.com>
Sun, 26 Sep 2021 21:46:04 +0000 (07:46 +1000)
committerGitHub <noreply@github.com>
Sun, 26 Sep 2021 21:46:04 +0000 (23:46 +0200)
* Update the Jinja2Templates() to allow PathLike

* Update templating.py

* Update starlette/templating.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
* Update starlette/templating.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
* Update starlette/templating.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
* Update starlette/templating.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
starlette/templating.py

index 36f613fdfd9481f0bd7ca7f471c523d5bf9f61be..18d5eb40c0f39484b6ee899f36c9a2dbccb2e1dd 100644 (file)
@@ -1,4 +1,5 @@
 import typing
+from os import PathLike
 
 from starlette.background import BackgroundTask
 from starlette.responses import Response
@@ -54,11 +55,13 @@ class Jinja2Templates:
     return templates.TemplateResponse("index.html", {"request": request})
     """
 
-    def __init__(self, directory: str) -> None:
+    def __init__(self, directory: typing.Union[str, PathLike]) -> None:
         assert jinja2 is not None, "jinja2 must be installed to use Jinja2Templates"
         self.env = self._create_env(directory)
 
-    def _create_env(self, directory: str) -> "jinja2.Environment":
+    def _create_env(
+        self, directory: typing.Union[str, PathLike]
+    ) -> "jinja2.Environment":
         @pass_context
         def url_for(context: dict, name: str, **path_params: typing.Any) -> str:
             request = context["request"]