inflearn logo
강의

Course

Instructor

Django REST Framework Essentials

Formatting PostList Output

The serializer field might be named incorrectly and not match any attribute or key on the `User` instance.

840

daniel

58 asked

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

django rest-api

Answer 1

0

bestdjango

안녕하세요. 독자님.

두번째 사진의 class PostListAPIView() 에서, 

queryset = Post.~ 라야 하는데, queryset = User.~ 로 되어 있는게 문제 입니다.

PostListSerializer 를 만들 때 Post 테이블을 사용해야 하는데 User 테이블을 지정해서,

위와 같은 에러 메세지가 난 것입니다.

확인 바랍니다.

블로그 첫 화면이 안 나옵니다.

0

317

3

INSTALLED_APPS 순서

0

246

1

vscode 실행안됨

0

667

3

django venv activate 하고 나서 vue 서버도 실행 해야 하나요?

0

367

2

더 공부할게있을까요

0

369

1

용어에 대해 문의 드립니다.

0

283

2

like 기능을 위한 overriding 문의

0

322

1

코드 최적화 과정

0

364

1

유저 1명이 1개의 게시글에 좋아요를 누를 경우

0

356

1

프로잭트를 생성하고 runserver하면 ModuleNotFoundError: No module named 발생해요

0

894

4

GET Method 에서 왜 Like 수를 증가시키는지 궁금합니다.

0

376

1

CSRF Token에 대한 질문입니다.

0

609

1

ModuleNotFoundError: No module named 'rest_framework django' 오류

0

3037

1

앱을 구성할 때 api 앱과 blog 앱을 나누어서 구성하는 이유가 궁금합니다ㅜ

1

472

2

to_representation() 오버라이딩 질문입니다.

0

496

3

공부 순서에 관해 질문드립니다.

0

360

1

CateTagAPIView에서 get 메소드

1

309

2

깃헙 페이지를 보고싶어요

0

230

1

디버거 관련 질문입니다.

0

277

3

가장 마지막강의 (Generic View -> ViewSet migration) 질문입니다.

0

223

1

PostCommentListAPIView(게시물 댓글 조회 api) 관련 질문

0

211

1

댓글 보기 및 삭제 api

0

280

1

post, comment crud 질문

0

228

4

CateTagSerializer 질문입니다!

3

336

3