📂drf
🔖drf
2022-09-29 11:18阅读: 39评论: 0推荐: 0

drf基础配置

安装

pip install djangorestframework

注册

INSTALLED_APPS = [
"rest_framework",
]

配置路由

urlpatterns = [
    path('auth/', views.auth),
    path('login2/', views.login2),
    path('login/', views.LoginView.as_view()),
]

视图

from rest_framework.decorators import api_view
from rest_framework.response import Response
from django.http import JsonResponse
from rest_framework.views import APIView
#django原始
def auth(request):
    return JsonResponse({'status': True, 'message': "success"})

#CBV
class LoginView(APIView):
    def get(self, request):
        return Response({'status': True, 'message': "success"})

#FBV
@api_view(['GET'])
def login2(request):
    return Response({'status': True, 'message': "success"})

image

本文作者:Sherwin

本文链接:https://www.cnblogs.com/sherwin1995/p/16740849.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Sherwin_szw  阅读(39)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
💬
评论
📌
收藏
💗
关注
👍
推荐
🚀
回顶
收起
  1. 1 404 not found REOL
404 not found - REOL
00:00 / 00:00
An audio error has occurred.