0
我正在從RetrieveAPIView中提取數據我想覆蓋它。如何覆蓋RetrieveAPIView響應django rest框架
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串行數據的方式,您的瀏覽不是如何返回它們。此外,您已發佈「本地網址」,127.0.0.1是您的本地網絡中的機器,而不是我們可以從其他地方看到或訪問的東西。 –
它只是一個簡單的RetrieveAPIView,我沒有實現任何邏輯。 https://www.youtube.com/watch?v=_GXGcc7XxvQ。我已經從這裏學習並實施了,但他沒有分享如何重寫它。 –
[如何在Django REST框架中返回自定義JSON]的可能的重複(http://stackoverflow.com/questions/35019030/how-to-return-custom-json-in-django-rest-framework) –