from django.shortcuts import render,HttpResponsefrom django.views import View # Create your views here. class LoginView(View): #form表单提交请求只能是get post #ajax提交请求 get post获取 put修改 patch修改 delete # def dispatch(self, request, *args, **kwargs): # print(‘dispath start ‘) # moethod=request.method.lower() # func=getattr(self,moethod) # print(‘dispath end ‘) # return func(request,*args,**kwargs) ‘‘‘ dispath核心代码 if request.method.lower() in self.http_method_names: handler = getattr(self, request.method.lower(), self.http_method_not_allowed) else: handler = self.http_method_not_allowed return handler(request, *args, **kwargs) ‘‘‘ def dispatch(self, request, *args, **kwargs): reponse=super(LoginView,self).dispatch(request, *args, **kwargs) return reponse def get(self,request,*args,**kwargs): print(‘get‘) return render(request,‘login.html‘) def post(self,request,*args,**kwargs): print(‘posrt‘) return HttpResponse(‘你好‘)
时间: 2024-10-25 16:03:04