一、指定序列化字段
设置fields = '__all__'
序列化所有字段。
class SnippetSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = '__all__' # 序列化所有字段
class SnippetSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ['student_no', 'student_name', 'student_sex', 'student_birthday', 'course', ] # 表示序列化指定字段
二、排除字段
class SnippetSerializer(serializers.ModelSerializer):
class Meta:
model = Student
exclude = ['student_name', 'student_sex', ] # 指定排除的字段
https://www.cnblogs.com/rainbow-tan/p/16339712.html
三、替换字段给前端
https://www.cnblogs.com/kaibindirver/p/16802477.html
标签:__,ModelSerializer,展示,student,serializers,序列化,class,drf From: https://www.cnblogs.com/kaibindirver/p/17227797.html