OVHcloud Community

Welcome to your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Django Rest Framework - Delete API CORS error in production mode (OVH web cloud)



I know this is a classic issue but I did not find a solution for my particular case. All APIs work fine, while the DELETE API fails with CORS error. This happens only in production environment (OVH web cloud) This is my python backend code:
`class UserDetail(APIView):

permission_classes = (IsAuthenticated,)

def get_object(self, pk):
return User.objects.get(pk=pk)
except User.DoesNotExist:
raise Http404

def get(self, request, pk, format=None):
userSet = User.objects.filter(id=pk)
serializer = UserSerializer(userSet, many=True)
return Response(

def post(self, request, pk, format=None):
userSet = self.get_object(pk)
serializer = UserUpdateSerializer(userSet,
if serializer.is_valid():
return Response(
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

def delete(self, request, pk, format=None):
user = self.get_object(pk)
return Response({‘deleted user’: pk}, status=status.HTTP_204_NO_CONTENT)`
This is the .htaccess file put in django root folder:

If needed, I also share the response header content as displayed by the browser :slight_smile:

Error Message:

`Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

i also read this and implement: