这是我的密码
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')
看起来很简单。问题是什么?
2条答案
按热度按时间cgfeq70w1#
将其更改为
CharField
。ogq8wdun2#
将其更改为
CharField
并添加allow_blank=True