AttributeError: Got AttributeError when attempting to get a value for field `thumbnail_path` on serializer `PostWirteSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `Post` instance.
Original exception text was: 'Post' object has no attribute 'thumbnail_path'.
PostDetail 뷰로 보려고 했는데 위와 같은 에러가 떳다
Post 모델에서 thumbnail_path 컬럼을 확인해보면
thumbnail_path = serializers.CharField() 라고 되어있었는데
thumbnaill = serializers.ImageField(source="thumbnail.source" 로 고쳤더니
Post Detail 뷰가 잘 작동하는 것을 알 수 있다.
여기서 알게 된건
/api/posts/1 -> 동작o
/api/posts/1/ -> 동작o
/api/posts/2 -> 동작x
/api/posts/2/ -> 동작o
<int:1> 의 경우 끝에 /(슬래시)를 안붙여줘도 동작하는데
<int:2> 부터는 무조건 끝에 /(슬래시)가 있어야 동작한다.
'Django > error!' 카테고리의 다른 글
You are trying to add a non-nullable field '필드명' to post without a default 해결 (0) | 2022.02.14 |
---|---|
[error!] The `.update()` method does not support writable dotted-source fields (0) | 2022.02.03 |
[Django-Rest-Framwork] Postman에서 csrftoken 자동화하기 (0) | 2022.01.30 |
[Git] git add 취소하기, git commit 취소하기, git push 취소하기 (0) | 2022.01.30 |
'IntegrityError, Not NULL constraint failed' 문제 해결하기 (0) | 2022.01.29 |