I am building a backend authentication in Django-Rest_framework
using django-rest-auth
and REST framework JWT Auth and when I login I keep getting this error. What am I doing wrong?
AttributeError at /api/auth/login/
'ImageFieldFile' object has no attribute 'pk'
Request Method: POST
Request URL: http://127.0.0.1:8000/api/auth/login/
Django Version: 3.2.8
Exception Type: AttributeError
Exception Value:
'ImageFieldFile' object has no attribute 'pk'
Exception Location: D:\Python Workspace\Rest_Gama\venv\lib\site-packages\rest_framework_jwt\utils.py, line 86, in jwt_create_payload
Python Executable: D:\Python Workspace\Rest_Gama\venv\Scripts\python.exe
Python Version: 3.9.7
This is my models.py
from django.contrib.auth.models import AbstractUser
from django.db import models
class CustomUser(AbstractUser):
profile = models.ImageField(default='user_default_m.png', upload_to='profile/', blank=True)
dob = models.DateField(auto_now=False, auto_now_add=False, blank=True)
This is my serializers.py
from rest_auth.serializers import LoginSerializer as RestAuthLoginSerializer
from rest_framework import serializers
from users.models import CustomUser
class CustomUserDetailsSerializer(serializers.ModelSerializer):
class Meta:
model = CustomUser
fields = ('pk', 'first_name', 'last_name', 'email', 'profile', 'dob', 'date_joined', 'last_login')
read_only_fields = ('pk', 'email', 'date_joined', 'last_login')
class LoginSerializer(RestAuthLoginSerializer):
username = None
Try reinstalling REST framework JWT Auth
pip install djangorestframework-jwt
Documentations for reference -> here