Opened 3 weeks ago
Closed 3 weeks ago
#36731 closed Bug (wontfix)
Allow TemplateView classes to have an asynchronous get_context_data method
| Reported by: | rrobles | Owned by: | |
|---|---|---|---|
| Component: | Template system | Version: | 5.2 |
| Severity: | Normal | Keywords: | TemplateView, get_context_data, async |
| Cc: | Carlton Gibson | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Currently, you can't use an asynchronous get_context_data in a TemplateView because it throws the following error:
TypeError: context must be a dict rather than a coroutine.
I've proposed some changes in this Pull Request:
https://github.com/django/django/pull/20081
These changes include a check to see if the context is a coroutine so it can be handled correctly in make_context. This allows you to handle get_context_data correctly when it's asynchronous.
Change History (3)
comment:1 by , 3 weeks ago
| Cc: | added |
|---|
comment:2 by , 3 weeks ago
comment:3 by , 3 weeks ago
| Resolution: | → wontfix |
|---|---|
| Status: | new → closed |
Thanks, Carlton.
Ricardo, I'm going to close this following the same rationale as Sarah's comment here: ticket:36194#comment:4, in which she specifically links to forum posts about templates and admin views not being worth asyncifying. I think the same holds for generic views. The last post on that forum thread discusses CBVs, but mostly the auth angle, which is different.
I think participating on that thread would be the place to make your case for this if after having a look you feel it has been overlooked and are not convinced.
Grrr. I think just writing the view by hand here is going to be better.
Duplicating the generic view APi as asynchronous is well beyond what we want to add in core here imo.