AttributeError at /users
Got AttributeError when attempting to get a value for field `id` on serializer `UserSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance.
Original exception text was: 'QuerySet' object has no attribute 'id'.
Request Method: GET
Request URL: http://127.0.0.1:8000/users
Django Version: 3.2.7
Exception Type: AttributeError
Exception Value:
Got AttributeError when attempting to get a value for field `id` on serializer `UserSerializer`.
The serializer field might be named incorrectly and not match any attribute or key on the `QuerySet` instance.
Original exception text was: 'QuerySet' object has no attribute 'id'.
- serializer는 한 개의 객체만 이해할 수 있고 리스트는 이해할 수 없기 때문이다.
objects.all()
은 객체들의 리스트를 리턴하므로many=True
옵션을 추가해줌으로써 해결
...
users = User.objects.all()
serializer = UserSerializer(users, many=True)
...
'잡다한 기술' 카테고리의 다른 글
[zookeeper] Apache Zookeeper? (0) | 2021.12.31 |
---|---|
[zookeeper] zookeeper에서 semaphore 사용하기 (0) | 2021.12.31 |
[zeppelin] Apache Zeppelin with Apache Spark? (0) | 2021.12.31 |
[git] ! [rejected] master -> master (non-fast-forward) 해결방법 (0) | 2020.02.02 |
구글 API 사용하기[Google Cloud Platform 사용하기] (9) | 2017.01.30 |