首页 > 其他分享 >Django rest_framework

Django rest_framework

时间:2023-02-23 15:11:21浏览次数:36  
标签:__ serializers rest Django framework 序列化 id

serializers

from rest_framework import serializers
class SerializerClass(serializers.ModelSerializer):
    class Meta:
        model = ModelClass
        # 1.序列化指定字段
        fields = ('id', 'name', 'sort',)
        # 2.序列化全部所有的字段
        # fields = '__all__'
        # 3. 序列化除了user以外的所有字段
        # exclude = ('user',)
        # 只读字段
        read_only_field = ('id', 'name', 'sort',)

标签:__,serializers,rest,Django,framework,序列化,id
From: https://www.cnblogs.com/congxinglong/p/17148038.html

相关文章