CBV与FBV

CBV与FBV

 

FBV

  FBV: function based view

  就是平常在views.py中写的函数

from django.shortcuts import render, HttpResponse

# Create your views here.
from django.http import JsonResponse


def test(request):
    user_dict = {'username': '阿飞', 'password': '123'}
    l = [111, 222, 333]
    return JsonResponse(l, safe=False)

CBV

  CBV: class based view

  写法:

class IndexView(View):
    def get(self, request):
        print('get')
        return HttpResponse('get')
    def post(self, request):
        print('post')
        return HttpResponse('POST')

  源码解析

 

   八大请求

 

END

posted @ 2022-03-02 18:43  Snails蜗牛  阅读(89)  评论(0编辑  收藏  举报