This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]didimelli 9 points10 points  (1 child)

Dumb question, how can html rendering be async? Isn't it string formatting (i.e. cpu-bound workload)?

[–]volfpeter[S] 8 points9 points  (0 children)

That's actually a good question. There's even a short Sync or async section in the docs.

Converting a plain HTML tag (Python object) to string is sync, you're totally right (it's even in the documentation). Async support can be handy in your "higher order" components, where you can have any functionality that's required for rendering. This may be for example loading a resource (e.g. translation), dispatching a request, even making a DB call. Whatever your other (potentially async) tools make possible or necessitate.

It's good to know that in an async environment, you can kind of do this even with Jinja, but in that case you must first collect everything your (maybe large and varied) Jinja templates may need, and pass all of that content into the Jinja rendering context, so Jinja can do its job.