我有一个使用Django Rest Framework JSON API的django 1.9.2项目:
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
Run Code Online (Sandbox Code Playgroud)
典型响应如下:
{"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": …Run Code Online (Sandbox Code Playgroud)