标签:war def pre rgs end views pos dispatch cbv
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
标签:war def pre rgs end views pos dispatch cbv
原文地址:https://www.cnblogs.com/L-dongf/p/11909344.html