I've added a call to UserSerializer This is my Serializer
class UserSerializer(serializers.ModelSerializer):
class Meta:
model=user
fields="__all__"
My Custom Model
from django.db import models
class user(models.Model):
username=models.CharField(max_length=150)
firstname=models.CharField(max_length=20)
lastname=models.CharField(max_length=20)
email=models.CharField(max_length=40)
password=models.CharField(max_length=40)
type=models.CharField(max_length=10)
def __str__(self):
return self.firstname
I have added a custom JWT Handler
from login.serializers import UserSerializer
def my_jwt_response_handler(token, user=None, request=None):
return {
'token': token,
'user': UserSerializer(user, context={'request':request}).data
}
And in settings.py I have
JWT_AUTH = {
'JWT_RESPONSE_PAYLOAD_HANDLER': 'login.utils.my_jwt_response_handler'
}
When I try to log in, I get this error?
AttributeError: Got AttributeError when attempting to get a value for field `firstname` on serializer `UserSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `User` instance.
Original exception text was: 'User' object has no attribute 'firstname'.
Any help would be appreciated
Have you migrated your database yet?
python manage.py makemigrationsandpython manage.py migrateI also recommend you take a look at this blog post showing how to use a custom user model within Django.
https://wsvincent.com/django-custom-user-model-tutorial/