首页 > 其他 > 详细

djano-cbv模式

时间:2018-01-02 10:53:29      阅读:270      评论:0      收藏:0      [点我收藏+]

cbv,class base view 就是用类写视图

详细用法替换fbv将在后续空余时间上补齐

fbv,function base view 就是用函数写视图

创建django app01项目

urls

1 urlpatterns = [
2     url(r^admin/, admin.site.urls),
3     url(r^login_cbv/, views.Login.as_view()),  # 注意写法
4 ]

 

views

 1 from django.views import View
 2 
 3 class Login(View):
 4 
 5     def get(self,request):
 6 
 7         return render(request,"login_cbv.html")
 8 
 9 
10     def post(self,request):
11         return HttpResponse("post.........")
12 
13 
14     def delete(self):
15         pass

 

login_cbv.html

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <meta http-equiv="X-UA-Compatible" content="IE=edge">
 6     <meta name="viewport" content="width=device-width, initial-scale=1">
 7     <title>Title</title>
 8 </head>
 9 <body>
10 
11 <form action="/login_cbv/" method="post">
12     {% csrf_token %}
13     <p><input type="text" name="user"></p>
14     <p><input type="submit"></p>
15 </form>
16 
17 </body>
18 </html>

 

djano-cbv模式

原文:https://www.cnblogs.com/jokerbj/p/8170807.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!