I'm getting 'No Access-Control-Allow-Origin header is present on the requested resource' even with all configured in Django Rest Framework
alac1984 opened this issue · comments
Even with all configurations made, when I try to access my DRF Api by XMLHttpRequest(using Axios), I'm getting the error below:
Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/posts' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
When I use Postman I do not have any errors whatsoever.
The code: https://gist.github.com/alac1984/60b984d208f4f2633c7aaf8e832fcf80
Did you read the linked articles in https://github.com/adamchainz/django-cors-headers#about-cors ?
99% of issues that I receive with "it doesn't work" about this library are due to misunderstanding of what CORS is and where you should apply it.
Did you read the linked articles in https://github.com/adamchainz/django-cors-headers#about-cors ?
99% of issues that I receive with "it doesn't work" about this library are due to misunderstanding of what CORS is and where you should apply it.
Yes, I sure did. I've been configuring DRF applications for some time right now. I've followed the steps like I always do... but with no success. This error is driving me crazy by now.
Just see the gist I've put above with my settings.py
to see that I've did everything that should be done.
Thanks for you time... I've found the error. Just a missing '/' in the end of the url.
Was it the URL in your settings, and should we have a guard against that?