- cbv:类、base、view
- fbc:函数、base、view
from django.contrib import admin
from django.urls import path
from app import views
urlpatterns = [
path('fbv/', views.fbv),
path('cbv/', views.CBV.as_view()),
]
from django.shortcuts import render,redirect,HttpResponse
from django.views import View
def fbv(request):
return HttpResponse("FBV")
class CBV(View):
def dispatch(self, request, *args, **kwargs):
result = super(CBV,self).dispatch(request, *args, **kwargs)
return result
def get(self,request):
return render(request,'cbv.html')
# return HttpResponse("CBV.GET")
def post(self,requset):
ret = HttpResponse("CBV.POST")
ret['h1'] = 'v1' #添加响应头
ret.set_cookie('c1','v2') #添加cookie
return ret
原文地址:https://www.cnblogs.com/L-dongf/p/11909344.html
时间: 2024-11-02 11:18:20