zoukankan      html  css  js  c++  java
  • 视图

    FBV:在视图中用函数

    CBV:在哪视图中用类

    CBV:

      定义: from django.views import view

         放到类的参数内  如:class AddPublisher(View):

      使用: url(r'^add_publisher/', views.AddPublisher.as_view()),

    给CBV加装饰器:

      1,from django.utils.decorators import method_decorator

        加载某个get/post的方法上:@method_decorator(timer)
                     def get(self, request):

        加在self.dispatch方法上:@method_decorator(timer)
                    def dispatch(self, request, *args, **kwargs):

        加在类上:     @method_decorator(timer, name='post')
                  @method_decorator(timer, name='get')
                  class AddPublisher(View):

    request

     1 常用属性:
     2 
     3 
     4 print(request.method)   # GET 请求方式
     5 print(request.GET)      # {}  []  get()     包含所有HTTP  GET参数的类字典对象
     6 print(request.POST)      # {}  []  get()    包含所有HTTP POST参数的类字典对象
     7 print(request.FILES)         #上传信息
     8 print(request.path_info,type(request.path_info))   # 路径信息   不包含IP和端口、参数
     9 常用方法:
    10 print(request.get_host()) #IP 端口
    11 print(request.get_full_path()) # 路径信息 + 参数 
  • 相关阅读:
    android开发:退出程序(对话框、两次返回键退出)
    【转】将HTML5封装成android应用APK 文件若干方法
    Linux语言修改
    Oracle用户常用数据字典
    成本控制:Oracle 优化器内幕
    [转]oraclemerge用法详解
    Show [SQL*Plus]
    【转】cron
    修改Linux主机名
    表空间删除
  • 原文地址:https://www.cnblogs.com/leo-tail-x/p/10067562.html
Copyright © 2011-2022 走看看