• djano-cbv模式


    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>
  • 相关阅读:
    MZOJ #72 数字
    MZOJ #71 maple做数学题
    MZOJ #70 FFF团
    luogu 2051 [AHOI2009]中国象棋
    uva 280
    uva 260
    文件的基本处理
    文件的基础
    Turtle库
    π的计算
  • 原文地址:https://www.cnblogs.com/jokerbj/p/8170807.html
Copyright © 2020-2023  润新知