CBV和FBV
阿新 • • 發佈:2017-09-15
reat att names form表單提交 put ret pos isp war
from django.shortcuts import render,HttpResponse
from 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(‘你好‘)
CBV和FBV