CBV和FBV
2018-12-10 本文已影响38人
乔治大叔
CBV基于类的视图(Class base view)和FBV基于函数的视图(Function base view)
from django.views import View
class AddPublish(View):
def dispatch(self, request, *args, **kwargs):
print(request)
print(args)
print(kwargs)
# 可以写类似装饰器的东西,在前后加代码
obj=super().dispatch(request, *args, **kwargs)
return obj
def get(self,request):
return render(request,'index.html')
def post(self,request):
request
return HttpResponse('post')