[Django] #36731: Allow TemplateView classes to have an asynchronous get_context_data method

10 views
Skip to first unread message

Django

unread,
Nov 14, 2025, 12:42:47 AM11/14/25
to django-...@googlegroups.com
#36731: Allow TemplateView classes to have an asynchronous get_context_data method
-------------------------------------+-------------------------------------
Reporter: rrobles | Type: Bug
Status: new | Component: Template
| system
Version: 5.2 | Severity: Normal
Keywords: TemplateView, | Triage Stage:
get_context_data, async | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36731>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 14, 2025, 1:03:00 PM11/14/25
to django-...@googlegroups.com
#36731: Allow TemplateView classes to have an asynchronous get_context_data method
-------------------------------------+-------------------------------------
Reporter: rrobles | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 5.2
Severity: Normal | Resolution:
Keywords: TemplateView, | Triage Stage:
get_context_data, async | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* cc: Carlton Gibson (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/36731#comment:1>

Django

unread,
Nov 14, 2025, 1:26:53 PM11/14/25
to django-...@googlegroups.com
#36731: Allow TemplateView classes to have an asynchronous get_context_data method
-------------------------------------+-------------------------------------
Reporter: rrobles | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 5.2
Severity: Normal | Resolution:
Keywords: TemplateView, | Triage Stage:
get_context_data, async | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Carlton Gibson):

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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36731#comment:2>

Django

unread,
Nov 14, 2025, 3:08:18 PM11/14/25
to django-...@googlegroups.com
#36731: Allow TemplateView classes to have an asynchronous get_context_data method
-------------------------------------+-------------------------------------
Reporter: rrobles | Owner: (none)
Type: Bug | Status: closed
Component: Template system | Version: 5.2
Severity: Normal | Resolution: wontfix
Keywords: TemplateView, | Triage Stage:
get_context_data, async | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* resolution: => wontfix
* status: new => closed

Comment:

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
[https://forum.djangoproject.com/t/is-dep009-async-capable-django-still-
relevant/30132/45 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.
--
Ticket URL: <https://code.djangoproject.com/ticket/36731#comment:3>
Reply all
Reply to author
Forward
0 new messages