注册DRF组件
安装
pip install djangorestframework -i https://pypi.douban.com/simple
注册settings
INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', ]
测试视图 views.py
1 from rest_framework.views import APIView 2 from rest_framework.response import Response 3 class TestAPIView(APIView): 4 def get(self,request): 5 return Response({"message":"hello"},)
urls.py
from django.urls import path from . import views urlpatterns = [ path("test", views.TestAPIView.as_view()) ]
要知道,你正在做的事情,对很多人都充满意义