Forums

Is there a way to enable CORS header in Django HttpResponse/JsonResponse?

I want to use my django app to provide REST APIs to my web app hosted on another site. So that web app can send ajax request to my Django app to get data. However the issue of CORS comes. The ajax request is always blocked by browser, because pythonanywhere donnot have CORS enabled with Django by default.. I found that you donnot have django-cors-headers installed by default and I cannot install it on console with 'pip install django-cors-headers' either. Because it says I donnot have permission.

Is there a way to enable CORS header in Django HttpResponse/JsonResponse?

Sorry I didn't check the Help page first. In fact there is already a solution to this issue. Just use 'pip install --user django-cors-headers' to workaround the permission denied issue. So this post can be closed.

I am also having same problem please help

The post just above yours has the solution.