I'm writing a custom user authentication for an app based on the Thinkster IO tutorial here: https://thinkster.io/django-angularjs-tutorial/
I've tweaked the user creation to use a confirmed password and then doing the save.
I thought I had everything working well, but I'm getting stuck on one error.
I believe that this is the problem code.
def create(self, validated_data):
# get the password or leave it alone
password = validated_data.get('password', None)
# get the confirm_password or leave it alone
confirm_password = validated_data.get('confirm_password', None)
# If the password exists AND the confirm password exists AND they eaqual each other
if password and confirm_password and password == confirm_password:
# create the object with valid form data
return models.Account.objects.create(**validated_data)
The error is: 'confirm_password' is an invalid keyword argument for this function
And it looks like it's being triggered by my view for the API. Any thoughts in why this is happening? It seems to me that this shouldn't be an issue as the check is in the view BEFORE the save and it just uses the password if it matches.
Any help would be great.
Here is the complete serializer
from django.contrib.auth import update_session_auth_hash
from rest_framework import serializers
from . . import models
class AccountSerializer(serializers.ModelSerializer):
password = serializers.CharField(write_only=True, required=False)
confirm_password = serializers.CharField(write_only=True, required=False)
class Meta:
model = models.Account
fields = ('id', 'email', 'username', 'created_at', 'updated_at',
'first_name', 'last_name', 'password',
'confirm_password',)
read_only_fields = ('created_at', 'updated_at',)
def create(self, validated_data):
# get the password or leave it alone
password = validated_data.get('password', None)
# get the confirm_password or leave it alone
confirm_password = validated_data.get('confirm_password', None)
# If the password exists AND the confirm password exists AND they eaqual each other
if password and confirm_password and password == confirm_password:
# create the object with valid form data
return models.Account.objects.create(**validated_data)
def update(self, instance, validated_data):
# get the username, if not changed that use the instance username
instance.username = validated_data.get('username', instance.username)
# update the instance
instance.save()
# get the password or leave it alone
password = validated_data.get('password', None)
# get the confirm_password or leave it alone
confirm_password = validated_data.get('confirm_password', None)
# If the password exists AND the confirm password exists AND they eaqual each other
if password and confirm_password and password == confirm_password:
# create the password with the password submitted
instance.set_password(password)
#save that instance with the updated password
instance.save()
# update the session so that the user does not need to login again
update_session_auth_hash(self.context.get('request'), instance)
# return the changed (or not changed) record
return instance