django-rest框架,json列表无效



我正在尝试为我的帖子添加标签。它工作得很好,但每当我创建序列化程序类(返回JSON数据(时,它都会引发如下错误:

{
"tags": [
"Invalid json list. A tag list submitted in string form must be valid json."
]
}

我使用的是django-taggitdjango-taggit-serializer软件包

我在settings.py 中安装的应用程序

INSTALLED_APPS = [
'rest_framework',
'rest_framework_gis',
'taggit',
'taggit_serializer'
]

我的型号.py

class Post(models.Model):
title= models.CharField(max_length=50)
description = models.TextField()
location = models.PointField(srid=4326)
tags = TaggableManager()

我的序列化程序.py

class PostCreateSerializer(TaggitSerializer,GeoFeatureModelSerializer):
tags = TagListSerializerField()
class Meta:
model = Post
geo_field = 'location' 
fields = [
'title','description','tags'
]

我的观点.py

class PostCreateApiView(CreateAPIView):
queryset = Post.objects.all()
serializer_class = PostCreateSerializer
message = 'you have not account'
permission_classes = [IsAuthenticated]
def perform_create(self,serializer):
serializer.save(user=self.request.user)

我看到过一些类似的问题,但它们对我的情况不起作用。我在PostGIS数据库中使用geodjango。我试图添加的数据:

{
"title": "my title",
"description": "nice desc",
"city": "city name",
"tags": tag1 tag2 tag3,
"location": POINT(-123.0208 44.0464)
}

我想问题出在发送数据的格式上。请尝试以列表格式而不是字符串格式发送标记。例如: { "title": "my title", "description": "nice desc", "city": "city name", "tags": ["tag1", "tag2", "tag3"], "location": POINT(-123.0208 44.0464) }

请检查此项以获取有关引发的异常的更多信息。

最新更新