前端传给后端的数据
{"name":"er毛流浪记","price":"55","publish":1,"authors":[1,2]}
1 接收前端传过来的数据,传到序列化类中
数据经过路由层(urls.py) ,到达视图层(views.py),首先要进行反序列化,将前端传过来的数据,传入到序列化类
ser = BookSerializer(data=request.data)
# request.data就是前端传过来的数据
2 前端传过来的数据,在序列化类中进行反序列化
"""
前端传过来的数据格式
{"name":"er毛流浪记","price":55,"publish":1,"authors":[1,2]}
在序列化类中,按照格式的不同,进行接收
name CharField
price IntegerField
publish IntegerField
authors ListField
"""
class BookSerializer(serializers.Serializer):
name = serializers.CharField()
price = serializers.IntegerField()
publish = serializers.IntegerField(write_only=True) # 反序列化 只写
auth