- 中文文档:
https://q1mi.github.io/Django-REST-framework-documentation/
- 神奇的generics
from snippets.models import Snippet
from snippets.serializers import SnippetSerializer
from rest_framework import generics class SnippetList(generics.ListCreateAPIView):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer class SnippetDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Snippet.objects.all()
serializer_class = SnippetSerializer在views.py中通过几行代码,就可以轻易的实现数据的curd操作,太酷了!
- 写restful api的步骤:
model -> serializer -> views -> url