I am trying to post data using DRF modelviewsets and Axios. I have tried a couple different options so far with the same result, 500. I am able to get data using axios.get but not able to post data. I am new to rest and using ajax so I apologize if it is something obvious.
Axios call
var csrftoken = Cookies.get('csrftoken');
axios({
method: 'post',
url: "/api/schedules/create",
data: {
"emp": this.emp.emp,
'start_time': this.startTime,
"end_time": this.endTime,
"date": this.today,
"location": this.location
},
headers : {"X-CSRFToken" : csrftoken }
})
},
Serializer
class SchedSerializer(serializers.ModelSerializer):
class Meta:
model = Schedule
fields = (
'location',
'emp',
'date',
'start_time',
'end_time'
)
View
class SchedViewSet(viewsets.ModelViewSet):
queryset = Schedule.objects.all()
serializer_class = serializers.SchedSerializer