发布数据时 Django REST API 中的 HTTP 400 错误请求

HTTP 400 Bad Request in Django REST API while posting data

我尝试使用 django restframework 通过 post 方法将一些数据 post 放入我的数据库,但我遇到了这个问题 HTTP 400 Bad Request : VM972 jquery-3.5。 1.min.js:2 POST http://127.0.0.1:8000/newmember/ 400(错误请求)

{
    "id":1,
    "first_name": "paul",
    "last_name": "scholes",
    "discipline": "football",
    "start_date": "01-01-2000",
    "end_date": "01-01-2012",
    "email": "paulscholes@gmail.com"
}

查看文件

@api_view(['POST'])
def insert_member(request):
    if request.method == "POST":
        # data = JSONParser().parse(request.data)
        member_serializer = MemberSerializer(data=request.data)
        if member_serializer.is_valid():
            member_serializer.save()
            return Response(member_serializer.data,status=201)
        return Response(member_serializer.data,status=400)

url 文件

urlpatterns = [
    path('admin/', admin.site.urls),
    path('equipments/', include('equipments.urls')),
    path('gym/',views.equipmentList.as_view()),
    path('newmember/', insert_member,name='insert_member'),
]

序列化文件

from rest_framework import serializers
from .models import Member```
    
class MemberSerializer(serializers.ModelSerializer):
    class Meta:
        model = Member
        fields = '__all__'

我已经通过在模型文件中设置 start_date 的类型来修复它:

start_date = models.DateTimeField(auto_now_add = True)

而不是

start_date = models.DateField(null=True)