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" 로 고쳤더니

 

/api/posts/1/

Post Detail 뷰가 잘 작동하는 것을 알 수 있다.

 

여기서 알게 된건

/api/posts/1 -> 동작o

/api/posts/1/ -> 동작o

 

/api/posts/2 -> 동작x

/api/posts/2/ -> 동작o

 

<int:1> 의 경우 끝에 /(슬래시)를 안붙여줘도 동작하는데

<int:2> 부터는 무조건 끝에 /(슬래시)가 있어야 동작한다.

 

delete 요청도 잘 동작한다.

+ Recent posts