这是我的代码
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')
看起来如此直截了当。有什么问题?
答案 0 :(得分:1)
将其更改为CharField
。
username = serializers.CharField(source="username", required = False)