前提:已经有Django环境
一、安装 pip install djangorestframework
二、编写视图
from django.http import JsonResponse
from rest_framework.views import APIView
# 用djangorestframework创建post接口时需要继承APIView class caseInfo(APIView): def post(self, requset): return JsonResponse({"code": 2000000, "msg": "success"},content_type="application/json,charset=utf-8")
三、编写路由
urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^caseInfoPost/', caseInfo.as_view()), ]
四、访问测试