CBV模式
就是把之前的函数视图用类实现了
简单测试一下:
urls.py
#CBV模式
url(r'^login_cbv/$', views.Login_cbv.as_view()),
注意:这里的Login_cbv是类名,它必须后面调用as_view()
views.py
from django.views import View class Login_cbv(View): def get(self,request): #如果是get请求需要执行的代码 return render(request,"login_cbv.html") def post(self,request): #如果是post请求需要执行的代码 return HttpResponse(".....") def delete(self,request): pass
login_cbv.html
<form action="/login_cbv/" method="post">
{% csrf_token %}
姓名:<input type="text">
<input type="submit">
</form>
对于form表单只支持post和get请求,对于ajax请求支持8种,
http_method_names = ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'trace']
posted on 2018-11-21 14:57 castiel_lee 阅读(70) 评论(0) 收藏 举报
浙公网安备 33010602011771号