你好,我正在创建一个要注册的api,但是我收到了这个错误
User() got an unexpected keyword argument 'firstname'
我尝试了很多方法,但都无法修复,如果有人能帮我修复,我将不胜感激。我的代码:
from rest_framework import serializers
from django.contrib.auth.models import User
from django.contrib.auth import get_user_model
User = get_user_model()
# User Serializer
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'first_name', 'last_name' ,'username', 'email', 'is_business')
# Register Serializer
class RegisterSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id','first_name' ,'last_name' , 'username', 'brand', 'email', 'is_business', 'password')
extra_kwargs = {'password': {'write_only': True}}
def create(self, validated_data):
user = User.objects.create_user(validated_data['username'],
firstname=validated_data['first_name'],
lastname=validated_data['last_name'],
brand=validated_data['brand'],
email=validated_data['email'],
password=validated_data['password'])
return user
1条答案
按热度按时间w9apscun1#
你打电话给我的是
firstname=
而不是first_name=
这可能是根本原因试试像这样的东西