AttributeError while using Django Rest Framework with serializers

前端 未结 2 494
长情又很酷
长情又很酷 2021-02-02 07:36

I am following a tutorial located here that uses Django Rest Framework, and I keep getting a weird error about a field.

I have the following model in my models.py<

2条回答
  •  春和景丽
    2021-02-02 08:06

    Simple specify many=True when creating a serializer from queryset, TaskSerializer(tasks) will work only with one instance of Task:

    tasks = Task.objects.all()
    serializer = TaskSerializer(tasks, many=True)
    

提交回复
热议问题