'React django permissions

I am still new in react when I tried to delete an element from API(django rest framework) in my case it's not working Error message : Access to XMLHttpRequest at 'http://127.0.0.1:8000/api/events/delete/3' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.enter image description here



Solution 1:[1]

pip install django-cors-headers 

#in settings.py
INSTALLED_APPS = [
    ...,
    "corsheaders",
    ...,
]
MIDDLEWARE = [
    ...,
    "corsheaders.middleware.CorsMiddleware",
    "django.middleware.common.CommonMiddleware",
    ...,
]

CORS_ALLOWED_ORIGINS = ["http://localhost:3000"]

Solution 2:[2]

I had the exact same problem. I wasn't putting slash '.../' at the end of the address.

deleteChat = async (id) => {
    let data = await api.delete(`/${id}/`)
}

Hopefully that helps.

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 mehedi
Solution 2 Martin Georgiev