【发布时间】:2017-09-23 20:51:24
【问题描述】:
我正在从 RetrieveAPIView 获取数据,我想覆盖它。
class PostDetailAPIView(RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = 'slug'
http://127.0.0.1:8000/api/posts/post-python/
返回结果
{
"id": 2,
"title": "python",
"slug": "post-python",
"content": "content of python"
}
我想用一些额外的参数来覆盖它
[
'result':
{
"id": 2,
"title": "python",
"slug": "post-python",
"content": "content of python"
},
'message':'success'
]
【问题讨论】:
-
你想改变你的 PostDetailSerializer 序列化数据的方式,而不是你的 View 如何返回它们。此外,您已经发布了您的“本地 url”,127.0.0.1 是您在本地网络中的机器,不是我们可以从其他地方看到或访问的东西。
-
它只是一个简单的 RetrieveAPIView,我没有实现任何逻辑。 youtube.com/watch?v=_GXGcc7XxvQ。我从这里学习并实现了相同的,但他没有分享如何重写它。
标签: django django-rest-framework