“'AttributeError: ‘WSGIRequest’ object has no attribute ‘is_ajax’” when trying to use django with google map api when developing a website

I am currently following along with a tutorial (https://www.youtube.com/watch?v=wCn8WND-JpU) that utilizes Django, python, and front-end languages to develop a website with Google Maps API.

This is for a project I want to pursue, but when I finished all the code it gave an error of:

‘WSGIRequest’ object has no attribute ‘is_ajax’ when trying to get past the sign-in page.

I reached out to the YouTuber and he gracefully told me I needed to replace the ‘request.is_ajax()’ to request.META. on the views.py. I tried doing that but it is still not working.

Could anyone be able to help me resolve this problem?

Here is the file he told me I needed to change the is_ajax:

If anyone needs more information, please let me know! I 100% followed along the tutorial from start to finish.

Hi, is_ajax is deprecated since django 3.1

See the release notes here Django 3.1 release notes | Django documentation | Django for alternative methods.

Hello, it seems like I could use “request.headers.get(‘x-requested-with’) == ‘XMLHttpRequest’” instead. Where would I need to place that in my code?

At the exact place where you would have use request.is_ajax(), replace by request.headers.get("x-requested-with") == "XMLHttpRequest"

THANK YOU!!! It works! Please have a wonderful day!