400 (Плохой запрос Vue Js, axios и Django rest framework для POST и PUT метода

enter image description here

Мои запросы Get и Delete работают отлично. Но, получаю 400 Bad request при вызове метода POST или PUT. И для вашего сведения, мой Django rest framework работает нормально в POST-MAN и в моем локальном http://127.0.0.1:8000/doctor. Я также прилагаю фотографию моей локальной машины. enter image description here enter image description here

Это работает нормально. В моем коде Axios:

data(){
    return{
        doctors:[],
        modalTitle:"",
        DoctorName:"",
        DoctorId:0,
        DoctorNameFilter:"",
        DoctorIdFilter:"",
        doctorsWithoutFilter:[]
    }
},
methods:{
    refreshData(){
        axios.get(variables.API_URL+"doctor/")
        .then((response)=>{
            this.doctors=response.data;
            this.doctorsWithoutFilter=response.data;
        });
    },
    addClick(){
        this.modalTitle="Add Doctor";
        this.DoctorId=0;
        this.DoctorName="";
    },
    editClick(doc){
        this.modalTitle="Edit Doctor";
        this.DoctorId=doc.id;
        this.DoctorName=doc.name;
    },
    createClick(){
        axios.post(variables.API_URL+"doctor/",Qs.stringify({

            data:this.DoctorName
        }))
        .then((response)=>{
            this.refreshData();
            alert(response.data);
        });
    },
    updateClick(){
        axios.put(variables.API_URL+"doctor/"+this.DoctorId, Qs.stringify({

            data:this.DoctorName
        }))
        .then((response)=>{
            this.refreshData();
            alert(response.data);
        });
    },
    deleteClick(id){
        if(!confirm("Are you sure?")){
            return;
        }
        axios.delete(variables.API_URL+"doctor/"+id)
        .then((response)=>{
            this.refreshData();
            alert(response.data);
        });

    },
    FilterFn(){
        var DoctorIdFilter=this.DoctorIdFilter;
        var DoctorNameFilter=this.DoctorNameFilter;

        this.doctors=this.doctorsWithoutFilter.filter(
            function(el){
                return el.DoctorId.toString().toLowerCase().includes(
                    DoctorIdFilter.toString().trim().toLowerCase()
                )&&
                el.DoctorName.toString().toLowerCase().includes(
                    DoctorNameFilter.toString().trim().toLowerCase()
                )
            });
    },
    sortResult(prop,asc){
        this.doctors=this.doctorsWithoutFilter.sort(function(a,b){
            if(asc){
                return (a[prop]>b[prop])?1:((a[prop]<b[prop])?-1:0);
            }
            else{
                return (b[prop]>a[prop])?1:((b[prop]<a[prop])?-1:0);
            }
        })
    }

},
mounted:function(){
    this.refreshData();
}

}

Мой Django settings.py:

В моем view.py :

    from django.shortcuts import render, HttpResponse
from .models import Doctors, Appointment
from .serializers import DoctorsSerializer, AppointmentSerializer
from django.http import JsonResponse
from rest_framework.parsers import JSONParser
from rest_framework.decorators import api_view, permission_classes
from rest_framework.response import Response
from rest_framework import status, generics
from rest_framework import permissions
from rest_framework.decorators import APIView


# from django.views.decorators.csrf import csrf_exempt

@permission_classes((permissions.AllowAny,))
class DoctorList(generics.ListCreateAPIView):
    queryset = Doctors.objects.all()
    serializer_class = DoctorsSerializer


@permission_classes((permissions.AllowAny,))
class DoctorDetails(generics.RetrieveUpdateDestroyAPIView):
    queryset = Doctors.objects.all()
    serializer_class = DoctorsSerializer

В моем urls.py:

    from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns
from appointment import views
# from .views import DoctorList, DoctorDetails
# from .views import doctor_list, doctor_details, appointment_list, appointment_details

urlpatterns = [
    path('doctor/', views.DoctorList.as_view()),
    path('doctor/<int:pk>', views.DoctorDetails.as_view()),
    # path('appointment/', AppointmentList.as_view()),
    # path('appointment/<int:pk>', AppointmentDetails.as_view()),

]
Вернуться на верх