Answer the question
In order to leave comments, you need to log in
How to determine in django that an ajax request is an XMLHttpRequest?
How to determine in a view that the request came using ajax, or rather, through javascript XMLHttpRequest or fetch?
Since I use javascript, the if request.is_ajax() check in django does not work, because false.
Answer the question
In order to leave comments, you need to log in
Since the ajax request was made on javascript, and not on jQuery, it was necessary to manually add the necessary attribute to the request header so that django would define request.is_ajax()
fetch('http://127.0.0.1:8000/main/katalog/5/', {
method: 'GET',
headers: {'X-Requested-With': 'XMLHttpRequest'}});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question