Django Rest Framework:使用ListField创建序列化程序会导致循环依赖错误



我是Django和Rest Framework的新手。我正在遵循有关序列化程序的文档,并尝试创建一个ListField(https://www.django-rest-framework.org/api-guide/fields/#listfield)当我这样做的时候,我会得到一个讨厌的循环导入错误

django.core.exceptions.ImproperlyConfigured: The included URLconf 'api.urls' does not appear to have any patterns in it. If you see valid patterns in the file then the issue is probably caused by a circular import.

我的序列化程序文件显示为:

class CapacitySerializer(serializers.Serializer):
planeIds = serializers.ListField(
planeId = serializers.IntegerField(min_value=0, max_value=10)
)
passangerNums = serializers.ListField(
passangerNum = serializers.IntegerField(min_value=0)
)
litersPerMinute = serializers.FloatField(required=False)
minutesOfFlight = serializers.FloatField(required=False)

如果我简单地将代码保留为:,代码就会工作

class CapacitySerializer(serializers.Serializer):
planeId = serializers.IntegerField(min_value=0, max_value=10)
passangerNum = serializers.IntegerField(min_value=0)
litersPerMinute = serializers.FloatField(required=False)
minutesOfFlight = serializers.FloatField(required=False)

知道为什么会出现这个错误吗?此外,如果我希望我的数据是planeIds和passengerNums的列表,这不是一个好方法吗?

版本:Django==3.0.4djangorestframework==3.11.0

链接的文档需要使用子参数。子项是必需的,而不是占位符名称

相关内容

  • 没有找到相关文章

最新更新