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

时间:2015-01-30 11:42:44

标签: django django-rest-framework

这是我的代码

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')

看起来如此直截了当。有什么问题?

1 个答案:

答案 0 :(得分:1)

将其更改为CharField

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