注册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())
]

 

posted @ 2022-07-25 15:07  阿U-root  阅读(30)  评论(0)    收藏  举报