I have this url in my urls.py
path('foo/bar/api', foo.APIBar.as_view(), name='foo-bar-api'),
and in my view.py I have this class that hands the api:
class APIBar(APIView):
def post(request, self, format=None):
date= request.POST['date']
person= get_object_or_404(Person, id=request.POST['person'])
return Response(status=status.HTTP_201_CREATED)
And I'm trying to send this ajax:
$.ajax({
url: "{% url 'foo-bar-api' %}",
method: "POST",
data: {
date: date.val(),
person: person.val()
}
});
But Django it's giving this error to me:
AttributeError: 'APIBar' object has no attribute 'POST'
I don't know why this is happening. I used the same structure in other models and works like a charm, but this one it's giving this error.
Please, can you tell me what am I doing wrong? I spent some hours trying to fix this error.