The HttpRequest.is_ajax() method is deprecated as it relied on a jQuery-specific way of signifying AJAX calls, while current usage tends to use the JavaScript Fetch API. Depending on your use case, you can either write your own AJAX detection method or use the new HttpRequest.accepts() method if your code depends on the client Accept HTTP header.
Asked
Active
Viewed 3,160 times
4
-
what is the actual question being asked? – dangel Dec 31 '22 at 01:42
2 Answers
4
def is_ajax(request):
return request.headers.get('x-requested-with') == 'XMLHttpRequest'

Dimitris Kougioumtzis
- 2,339
- 1
- 25
- 36
3
If you are writing your own AJAX detection method, request.is_ajax() can be reproduced exactly as
if request.headers.get('X-Requested-With') == 'XMLHttpRequest':
is_ajax = True
else:
is_ajax = False

Ayaz Ur Rashid
- 221
- 3
- 9