[Django] #36909: Avoid using context.request directly

1 view
Skip to first unread message

Django

unread,
Feb 7, 2026, 6:44:41 PM (16 hours ago) Feb 7
to django-...@googlegroups.com
#36909: Avoid using context.request directly
-----------------------------+-------------------------------------------
Reporter: Jake Howard | Type: Bug
Status: new | Component: Template system
Version: 5.1 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-----------------------------+-------------------------------------------
The `RequestContext` subclass sets `context.request` to the current
request object. This attribute isn't available when `Context` is used, or
when something context-looking is used instead. For example, the new
`querystring` tag accesses `context.request`, making it incompatible in
some cases.

I'd suggest that uses of `context.request` directly be replaced with
`context["request"]`, and that `RequestContext` automatically add
`request` to its own context if it's not there already. It might also be
worth renaming the attribute to `_request` to hint it shouldn't be used
externally.

This likely only occurs when template context is being incorrectly
handled, but it's likely worth improving regardless.
--
Ticket URL: <https://code.djangoproject.com/ticket/36909>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 7, 2026, 8:22:55 PM (14 hours ago) Feb 7
to django-...@googlegroups.com
#36909: Avoid using context.request directly
---------------------------------+--------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by jaffar Khan):

* cc: jaffar Khan (added)

Comment:

Like to work on it if accepted.
--
Ticket URL: <https://code.djangoproject.com/ticket/36909#comment:1>

Django

unread,
2:39 AM (8 hours ago) 2:39 AM
to django-...@googlegroups.com
#36909: Avoid using context.request directly
---------------------------------+--------------------------------------
Reporter: Jake Howard | Owner: (none)
Type: Bug | Status: new
Component: Template system | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+--------------------------------------
Comment (by Vidhi Singh):

This seems like a reasonable cleanup to avoid relying on context.request,
which isn’t always present.
I’m happy to work on a patch if maintainers agree with the proposed
direction.
--
Ticket URL: <https://code.djangoproject.com/ticket/36909#comment:2>

Django

unread,
2:44 AM (8 hours ago) 2:44 AM
to django-...@googlegroups.com
#36909: Avoid using context.request directly
---------------------------------+---------------------------------------
Reporter: Jake Howard | Owner: jaffar Khan
Type: Bug | Status: assigned
Component: Template system | Version: 5.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------------+---------------------------------------
Changes (by jaffar Khan):

* owner: (none) => jaffar Khan
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36909#comment:3>
Reply all
Reply to author
Forward
0 new messages