__init__() 得到了一个意外的关键字参数 'required' - Rest 框架模型序列化程序

__init__() got an unexpected keyword argument 'required' - Rest framework model serializer

这是我的代码

from rest_framework import serializers
from django.contrib.auth import get_user_model
User = get_user_model()

class UserSerializer(serializers.ModelSerializer):
    username = serializers.Field(source="username", required = False)   
    class Meta:
        model = User
        fields = ('first_name', 'last_name', 'username')

看起来很直接。有什么问题?

改为CharField

username = serializers.CharField(source="username", required = False)