码迷,mamicode.com
首页 > 其他好文 > 详细

CBV和FBV

时间:2017-09-15 16:43:09      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:fun   repo   tar   ret   class   attr   turn   end   response   

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

标签:fun   repo   tar   ret   class   attr   turn   end   response   

原文地址:http://www.cnblogs.com/tiantao36/p/7526772.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!