[Django]-POST API response blocked by CORS policy – React and Django Rest Framwork

0👍

You don’t need to put access-control-allow-origin in your CORS_ALLOW_HEADERS.
The Django CORS will add automatically on requests based on your configurations.

Some tips you could try:

  • Use default_headers instead of put all default headers (just to improve the code)
  • I already had problems with some basic headers that Chrome was sending and my app didn’t allow them, so I had to add
from corsheaders.defaults import default_headers

CORS_ALLOW_HEADERS = default_headers + (
    'Cache-Control', 'If-Modified-Since',
)
  • Try adding “trusted origins”
CSRF_TRUSTED_ORIGINS = (
    '*.yourdomain.com',
)

0👍

Check out this lib. https://pypi.org/project/django-cors-headers. It helped me to solve the same problem with React.

Leave a comment