New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add env argument to Jinja2Templates, remove **env_options. (ref #2134) #2159
Conversation
I like this, it meets the "starlette has a simple opinionated way" need whilst also allowing the user to do something really complicated without the starlette project having to think about a new API at all - since it falls to a shared idea of the Jinja environment which is referenced and used in many different jinja projects. |
Can we deprecate the |
@@ -64,18 +65,27 @@ class Jinja2Templates: | |||
|
|||
def __init__( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we overload this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the overload and the rebase, we are done here 👍
starlette/templating.py
Outdated
self, | ||
directory: typing.Union[str, PathLike], | ||
**env_options: typing.Any, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self, | |
directory: typing.Union[str, PathLike], | |
**env_options: typing.Any, | |
self, directory: typing.Union[str, PathLike], **env_options: typing.Any |
I've rebased it. |
I had to make all other arguments as kw-only to make overloading work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Let's accept the context_processors
being a kw-only as a breaking change.
@@ -61,7 +61,7 @@ templates.env.filters['marked'] = marked_filter | |||
|
|||
## Using custom jinja2.Environment instance | |||
|
|||
Starlette also accepts a preconfigured `jinja2.Environment` instance. | |||
Starlette also accepts a preconfigured [`jinja2.Environment`](https://jinja.palletsprojects.com/en/3.0.x/api/#api) instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn't render very well on mkdocs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok. Great 👍
Thanks 👍 |
This PR adds
env
argument toJinja2Templates
class and removes**env_options
.Motivation
See this discussion - #2134
Jinja2Templates
configure only this class and nothing elsejinja2.Environment
and use it in the app without limitsEnvironment
class may be used by other app components, not just by StarletteThis is a breaking change!
Example