我使用Django的REST框架JSON API一個Django 1.9.2項目:如何在Django Rest Framework JSON API中生成JSON-API數據屬性與結果屬性?
https://github.com/django-json-api/django-rest-framework-json-api:
我的視圖集中看起來是這樣的:
class QuestionViewSet(viewsets.ReadOnlyModelViewSet):
"""
API endpoint that allows questions and answers to be read.
"""
resource_name = 'questions'
queryset = Question.objects.all()
serializer_class = QuestionSerializer
renderers = renderers.JSONRenderer
parsers = parsers.JSONParser
典型的反應是這樣的:
{"links": {"first": "http://testserver/api/v1/coaches?page=1", "last": "http://testserver/api/v1/coaches?page=1", "next": null, "prev": null}, "results": [{"id": 1, "created": "2016-02-11T02:41:22.569000Z", "updated": null, "deleted": null, "uuid": "0473c709-994f-465b-989e-407c623f365f", "user": {"type": "User", "id": "2"}}, {"id": 2, "created": "2016-02-11T02:41:46.853000Z", "updated": null, "deleted": null, "uuid": "36e19c0e-bda6-4bd7-bc73-374a6fc509d6", "user": {"type": "User", "id": "3"}}, {"id": 3, "created": "2016-02-11T02:42:05.419000Z", "updated": null, "deleted": null, "uuid": "d0798ff4-3be2-4cf3-81ac-edf8049eb075", "user": {"type": "User", "id": "4"}}], "meta": {"pagination": {"page": 1, "pages": 1, "count": 3}}}
我希望輸出具有數據屬性而不是結果屬性。我怎麼能告訴輸出這裏所描述的風格DRF JSON API:
所以問題變成與我所建議的不同?我很困惑:D – bmbigbang