-
-
Notifications
You must be signed in to change notification settings - Fork 903
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 AsyncTemplateResponse
to Jinja2Templates
#1701
Conversation
e164aad
to
19b660c
Compare
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 looks good, I'd wait for @tomchristie 's input on this too.
is this not valid anymore https://github.com/encode/starlette/blob/master/docs/templates.md#asynchronous-template-rendering ? |
Yeah I mentioned if this is going to be merged the docs should be updated. |
|
||
templates = Jinja2Templates(directory='templates', enable_async=True) | ||
|
||
async def get_name(): |
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'd suggest some kind of comment noting that this'd actually only make sense in the case of an actual async operation. (Eg. an async database lookup.)
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.
Ok, thanks for your advice.
Subjective. Personally I think it's probably decent advice. But. 🤷♂️ |
routes=[Route("/", endpoint=homepage)], | ||
) | ||
templates = Jinja2Templates(directory=str(tmpdir), enable_async=True) | ||
templates.env.globals["get_name"] = get_name |
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.
Why is this not added on line 46?
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 also need to tweak a bit the documentation, as the introduced section doesn't connect well with the previous section. 🤔
@amisadmin Are you still interested on working on this PR? |
Yes, I am. But I'm a terrible document writer. |
Co-authored-by: Amin Alaee <[email protected]>
Co-authored-by: Marcelo Trylesinski <[email protected]>
Co-authored-by: Marcelo Trylesinski <[email protected]>
I'm going to pass on this for the time being. We can come back to this after 1.0 is released. Thanks for the PR, and sorry for the waiting time. |
Help Jinja2 make it easier and faster to use async template rendering.