CBV

1、基于类的视图(推荐)

from django.shortcuts import render,HttpResponse
from django.views import View

# Create your views here.


class TestView(View):

    def get(self, request):
        return render(request, "test.html")

    def post(self, request):
        return HttpResponse("Post")
path('test/', views.TestView.as_view()),

2、方法

 http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
'get', 'post', 'put', 'patch', 'delete'最常用
put和patch都是修改数据时使用,区别 put全部修改 patch部分修改
posted @ 2019-09-03 07:10  市丸银  阅读(676)  评论(0编辑  收藏  举报