So I made a POST method but everytime I try to send a request I get this error.

This is my method

@api_view(['POST'])
def CreateCustomService(request):
x=CustomService.objects.create(  
    Title=request.data['Title'], 
    Description=request.data['Description'],
    PreConditions=request.data['PreConditions'],
    Duration=request.data['Duration'],
    HomeSampling=request.data['HomeSampling'],
    HomeSamplingPrice=request.data['HomeSamplingPrice'], 
    Communication=request.data['Communication'],
    CommunicationPrice=request.data['CommunicationPrice'],
    ServicePrice=request.data['ServicePrice'],
)

jsonobject=CustomServiceSerializer(x) 
return Response("DATA STORED")

And this is the request that I am trying to send

POST http://127.0.0.1:8000/Inventory/CreateCustomService HTTP/1.1
Content-Type: application/json

{
        "Title": "TbGold",
        "Description": "Done to detect TB",
        "PreConditions": ["Drink water"],
        "Duration":"30 mins",
        "HomeSampling": "True",
        "HomeSamplingPrice":  200,
        "Communication":  "True",
        "CommunicationPrice": 100,
        "ServicePrice": 18000,
}

This is my Model

class CustomService(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
Title = models.CharField(max_length=100)
Description = models.TextField()
PreConditions = ArrayField(models.CharField(
    max_length=100), blank=True, null=True)

Duration = models.DurationField()
HomeSampling = models.BooleanField(default=False)
HomeSamplingPrice = models.IntegerField(default=0)
Communication = models.BooleanField(default=False)
CommunicationPrice = models.IntegerField(default=0)
ServicePrice = models.IntegerField(default=0)

def __str__(self):
    return self.Title

Error when I open url

Error when I send request through test.http file

🔴 No definitive solution yet
📌 Solution 1
0

This error is most likely occuring from the post request being redirected as in this post django-rest-framework - POST Request returns "Method \"GET\" not allowed."