Irregular arbitrarily Cross-Origin request blocked error in Django on Ionos hosting

I currently make a project for School where I made a Quiz. The Quiz is supposed to evaluate in the front-end, wich works perfectly fine, and after that it should send the informations to the backend. THe Backend should save the details to the database and after that it should send the informations back to the front end. The front end should show a message with some details about how you passed compared to all the others, the informations are the one from the database. So, the weird thing about all that is, that it works sometimes and sometimes not... If I test it at the local host, the code works perfectly fine, the error only occurs on the Ionos server (I got a hosting contract so I do not have access to the console...). Here is btw. the Link to my website: https://tor-netzwerk-seminarfach2024.com/ .If you click in the upper left corner and then on the quiz buttonm, you will get to the quiz. If I look at the console and network analytics and I got the "luck" that the error ouccurs the following message shows up:

Cross-Origin request blocked: The same source rule prohibits reading the external resource on https://api. tor-netzwerk-seminarfach2024. com/apache-test/. (Reason: CORS request failed).

https://api.tor-netzwerk-seminarfach2024.com/apache-test/ is my backend and https://tor-netzwerk-seminarfach2024.com/ my frontend. The settings file in Django is not the problem. To make it clear one more time, the error does not occur always.Sometimes you have to go again to the website and make it one time or two times more until you get the error...

If I look at the network analytics, than I see that the client request works as usal, but the answer field from the server is completly empty.-. Lets move on to the weirdest part of all: The Data actually gets saved in the Database, there is just sometimes no response? It would be wayyy to much for a minimum working product but here is the most important code- if you want to test it you can just take the link to my Website:https://tor-netzwerk-seminarfach2024.com/

--Server side with Django---

from rest_framework.response import Response
from .models import Lead
import json
from .serializer import TestingSerializer


def updateDigits():
    leadObj = Lead.objects.all()
    currentScore = leadObj[0].sumScore; currentRequests = leadObj[0].sumRequests
    valueBtnOne = leadObj[0].buttonOne; valueBtnTwo = leadObj[0].buttonTwo;
    valueBtnThree = leadObj[0].buttonThree; valueBtnFour = leadObj[0].buttonFour;
    valueBtnFive = leadObj[0].buttonFive; valueBtnSix = leadObj[0].buttonSix;
    valueBtnSeven = leadObj[0].buttonSeven; valueBtnEight = leadObj[0].buttonEight;
    valueBtnNine = leadObj[0].buttonNine; 
    return [valueBtnOne,valueBtnTwo,valueBtnThree,valueBtnFour,valueBtnFive,valueBtnSix,valueBtnSeven,valueBtnEight,valueBtnNine,currentScore,currentRequests]

@api_view(["POST"])
def home(request):
    
    body_unicode = request.body.decode('utf-8')
    body = json.loads(body_unicode)
    result = body["Result"]
    isItRight = body["wichOnesRight"]

    ip_adress = get_client_ip(request)
    queryset = Lead.objects.all()

    if Lead.objects.all().exists():
            currentValues = updateDigits()
            
            queryset.update(
                sumScore = result + currentValues[9],
                sumRequests = 1 + currentValues[10],
                buttonOne = currentValues[0] + isItRight[0],
                buttonTwo = currentValues[1] + isItRight[1],
                buttonThree = currentValues[2] + isItRight[2],
                buttonFour = currentValues[3] + isItRight[3],
                buttonFive = currentValues[4] + isItRight[4],
                buttonSix = currentValues[5] + isItRight[5],
                buttonSeven = currentValues[6] + isItRight[6],
                buttonEight = currentValues[7] + isItRight[7],
                buttonNine = currentValues[8] + isItRight[8],
                )
            currentValues = updateDigits()
    else:
            obj = Lead()
            obj.save()
    serializer = TestingSerializer(queryset[0], many =False)

    return Response({**serializer.data, "myResult": result})

my Django model:

from django.db import models

class Lead(models.Model):
    sumScore = models.IntegerField(default=0)
    sumRequests = models.IntegerField(default=0)
    buttonOne =  models.IntegerField(default=0)
    buttonTwo =  models.IntegerField(default=0)
    buttonThree =  models.IntegerField(default=0)
    buttonFour =  models.IntegerField(default=0)
    buttonFive =  models.IntegerField(default=0)
    buttonSix =  models.IntegerField(default=0)
    buttonSeven =  models.IntegerField(default=0)
    buttonEight =  models.IntegerField(default=0)
    buttonNine =  models.IntegerField(default=0)

serializer just serializes _ _ all _ _ ...

---Front end with React---

function evaluateAndCheckQuiz(){
    let countNotChosen = howManyNotChosen()
    
    if(countNotChosen){ answerQuestions(countNotChosen); return }
    
    let points = evaluateQuiz()

    document.getElementById("scoreText").style.display = "block"
    document.getElementById("scoreNumber").textContent = points

    return points
}

--Calling sendAndGetQuizAverage with evaluateAndCheckQuiz as a parameter--

function sendAndGetQuizAverage(points){
    const myPostRequest = {
        method: 'POST',
        headers: {'Content-Type': 'application/json'},
        body: JSON.stringify({"Result":points, "wichOnesRight": wichOnesRight}),
        };
    let data
    fetch('https://api.tor-netzwerk-seminarfach2024.com/apache-test/', myPostRequest).then(
         (response) => data = response.json()).then(
         (data) => {showResultAnalyse(data)})
}

function showResultAnalyse(data){
    console.log(data)
    let averageScore = (data["sumScore"] / data["sumRequests"]).toFixed(2)
    let myResult = data["myResult"]
    changeLinksToStatistics([
        data["buttonOne"],data["buttonTwo"],data["buttonThree"],
        data["buttonFour"],data["buttonFive"],data["buttonSix"],
        data["buttonSeven"],data["buttonEight"],data["buttonNine"]
        ],
        data["sumRequests"]
    )
    
    swal(
        {
        text:`${checkWichText(myResult,averageScore,data["sumRequests"]  )}`,
        icon: myResult > averageScore ?"success": "error",
        button:"Oki doki",
        }
    );
}
Back to Top