#30997 closed Cleanup/optimization (fixed)
Deprecate HttpRequest.is_ajax.
Reported by: | Adam Johnson | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
As discussed on this django-developers thread this should be deprecated.
It inspects the non-standard header X-Requested-Wiith that is set by jQuery and maybe other frameworks. However jQuery's popularity, especially for making requests, is decreasing thanks to changes such as the new fetch()
JS API.
Also in the cases this property is used to determine the kind of content to send to a client, it'd be better to inspect the HTTP standard Accept
header.
For these reasons Flask has deprecated its similar property is_xhr
.
Change History (12)
comment:1 by , 5 years ago
Description: | modified (diff) |
---|---|
Summary: | Deprecate HttpRequest.is_ajax → Deprecate HttpRequest.is_ajax. |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 5 years ago
comment:3 by , 5 years ago
Has patch: | set |
---|
I modified a bit the requests.accept() PR to include what is IMHO needed before deprecating the is_ajax
method.
comment:5 by , 5 years ago
Yes, via a standard deprecation as per the policy: https://docs.djangoproject.com/en/dev/internals/release-process/#internal-release-deprecation-policy
The first step would be to document current limitations of the method.
Second step would be to avoid using it as much as possible in Django's own code.
Finally the deprecation can take place.
It remains to be shown how the request.accepts proposal can play a role here.
A good exercise would be to replace that example: https://docs.djangoproject.com/en/2.2/topics/class-based-views/generic-editing/#ajax-example (or would you simply remove it?)