Inflearn Community Q&A
The serializer field might be named incorrectly and not match any attribute or key on the `User` instance.
Written on
·
824
0
AttributeError at /api2/post/
Got AttributeError when attempting to get a value for field `title` on serializer `PostListSerializer`. 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 'title'.
위와 같은 에러가 발생합니다.
코드를 봤는데 이유를 잘 모르겠습니다...
답변을 주신다면 너무 좋을 것 같습니다
serializers.py

views.py

urls.py

Got AttributeError when attempting to get a value for field `title` on serializer `PostListSerializer`. 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 'title'.
위와 같은 에러가 발생합니다.
코드를 봤는데 이유를 잘 모르겠습니다...
답변을 주신다면 너무 좋을 것 같습니다
serializers.py

views.py

urls.py

djangorest-api
Answer 1
0
bestdjango
Instructor
안녕하세요. 독자님.
두번째 사진의 class PostListAPIView() 에서,
queryset = Post.~ 라야 하는데, queryset = User.~ 로 되어 있는게 문제 입니다.
PostListSerializer 를 만들 때 Post 테이블을 사용해야 하는데 User 테이블을 지정해서,
위와 같은 에러 메세지가 난 것입니다.
확인 바랍니다.





