Skip to content
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

Consider making starlette.templating.Jinja2Templates.get_env "protected" #1194

Closed
mristin opened this issue Jun 4, 2021 · 0 comments · Fixed by #1218
Closed

Consider making starlette.templating.Jinja2Templates.get_env "protected" #1194

mristin opened this issue Jun 4, 2021 · 0 comments · Fixed by #1218
Labels
clean up Refinement to existing functionality

Comments

@mristin
Copy link

mristin commented Jun 4, 2021

Hi,
Thank you very much for your project! We are using it intensively through FastAPI.

While I was exploring the code base and looking how to use Jinja2Templates, I noticed the method get_env. At first I thought it was a getter for the environment, but eventually realized it is only called in the constructor of the class.

It would make much more sense to me if the method was called _get_env. This would signal that it should not be used outside of the class (or at least that the caller needs to know what she is doing).

For example, if I want to add filters or globals to the environment, I should write:

templates = Jinja2Templates(...)
templates.env.globals[...] = ...

instead of:

templates = Jinja2Templates(...)
templates.get_env().globals[...] = ...

As of current implementation, the second snippet has no effect.

Thank you very much for considering this request!

@JayH5 JayH5 added the clean up Refinement to existing functionality label Jun 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clean up Refinement to existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants