【发布时间】:2020-08-07 00:52:48
【问题描述】:
我正在尝试为我的帖子添加标签。它工作正常,但每当我制作序列化程序类(返回 JSON 数据)时,它都会引发如下所示的错误:
{
"tags": [
"Invalid json list. A tag list submitted in string form must be valid json."
]
}
我正在使用django-taggit 和django-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)
我看到了一些类似的问题,但它们对我的情况不起作用。 我将 geodjango 与 PostGIS 数据库一起使用。 我要添加的数据:
{
"title": "my title",
"description": "nice desc",
"city": "city name",
"tags": tag1 tag2 tag3,
"location": POINT(-123.0208 44.0464)
}
【问题讨论】:
-
geo django 不太可能干涉这里。你发布什么数据?
-
有什么关系,想象它不是 geodjango,有答案吗?
-
服务器响应中已经给出了答案:发送标签列表,而不是字符串。如果您需要更多帮助,我们需要查看您发送的数据以确定
-
数据是:{ "title": "my title", "description": "nice desc", "city": "city name", "tags": tag1 tag2 tag3, "location ": POINT(-123.0208 44.0464) }
-
你看到this post了吗?
标签: django django-rest-framework django-taggit