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()) # 路径信息 + 参数 
  • 相关阅读:
    二分查找
    「数学」二次函数中项系数大小与图像的关系
    「数学」夹角公式
    「CF80A」Panoramix's Prediction
    「Luogu P6101」[EER2]出言不逊
    「数学」三角函数公式以及部分证明
    「Luogu P6069」[MdOI2020] Group
    「CF80B」Depression
    「数学」Menelaus定理与Ceva定理
    「AT1175」ニコニコ文字列
  • 原文地址:https://www.cnblogs.com/leo-tail-x/p/10067562.html
Copyright © 2011-2022 走看看