-
-
Notifications
You must be signed in to change notification settings - Fork 948
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
Allow env_options
in `Jinja2Templates
#1401
Conversation
) -> "jinja2.Environment": | ||
@pass_context | ||
def url_for(context: dict, name: str, **path_params: typing.Any) -> str: | ||
request = context["request"] | ||
return request.url_for(name, **path_params) | ||
|
||
loader = jinja2.FileSystemLoader(directory) | ||
env = jinja2.Environment(loader=loader, autoescape=True) | ||
env_options.setdefault("loader", loader) |
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.
We can decide if we want to allow loader to be passed in env_options or not. The point is if we add it it makes directory
reduntant but allows user full control over the loader.
env_options
in `Jinja2Templates
env_options
in `Jinja2Templates
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.
Neat. 👍
The documentation was not done yet. Can you check again? |
Yup - I oughta have noted that. 😅 |
Closes #427
Allows
Jinja2Templates
to set Jinja2Environment
options here.For example:
Or:
Since
directory
is still a required argument, it will be passed in this case, but the loader passed will take precedence over thedirectory
and the loader created by Starlette. I can't think of any way to handle this right now, until maybe we can consider another API for Jinja2Templates later. This way we can deal with issues like #1214 .