dispatch 方法可以直接在用户请求之前在一些事情,例如计算请求耗时,判断客户端请求头
class LoginView(View):
def dispatch(self, request, *args, **kwargs):
print('开始请求---->')
ret = super().dispatch(request,*args,**kwargs)
print('请求结束----->')
return ret
def get(self,request):
print('get')
return render(request,'login.html')
def post(self,request):
print('post')
username = request.POST.get('username')
password = request.POST.get('password')
return HttpResponse(username+password)