REST framework 基本使用
生活随笔
收集整理的這篇文章主要介紹了
REST framework 基本使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝
pip install djangorestframeworkdjangorestframework 介紹
-
djangorestframework 主要使用 APIView,其實APIView實質是對 View 進行繼承加工了更多功能
-
請求來了 APIView首先執行 self.dispatch 方法,此方法對 request 進行了再次封裝
基于django實現REST framework
urls.py
urlpatterns = [url(r'^users', Users.as_view()), ]views.py
from django.views import View from django.http import JsonResponseclass Users(View):def get(self, request, *args, **kwargs):result = {'status': True,'data': 'response data'}return JsonResponse(result, status=200)def post(self, request, *args, **kwargs):result = {'status': True,'data': 'response data'}return JsonResponse(result, status=200)參考鏈接于此
總結
以上是生活随笔為你收集整理的REST framework 基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: django解决跨域问题
- 下一篇: DjangoRestFramework基