'Django Rest Framework Endpoint Request Fails with Error Cross-Origin Request Blocked
I have a django rest application back end with an angular front end. All the endpoints work perfectly locally but when I deploy it to google cloud all endpoints works except one which keeps on displaying the error Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at url (Reason: CORS request did not succeed). I have tried to connect the database on the cloud with the local application, all the endpoints requests are displayed on the IDE console except the one, and the browser displays the request is not yet finished. Any ideas on what is causing the issue will be highly appreciated. I have gone through several similar questions on stackoverflow and tried to implement the solutions provided but it is not working. All my other endpoints are working perfectly its only one which displays the error on google cloud app engine, connected to a PostgreSQL standard instance 1vcpu,3.75GB RAM. When I try with POSTMAN I get the error 502 Bad Gateway
Solution 1:[1]
Install Django-cors-headers to solve this problem Follow this link: https://pypi.org/project/django-cors-headers/
- python -m pip install django-cors-headers
- INSTALLED_APPS = [ ..., "corsheaders", ..., ] add middleware top of the commonmiddle
- MIDDLEWARE = [ ..., "corsheaders.middleware.CorsMiddleware", "django.middleware.common.CommonMiddleware", ..., ]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sibtain |
