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()) # 路径信息 + 参数 
  • 相关阅读:
    放苹果
    滑雪-递归
    模数之和
    n个数的最小公倍数
    webapi跨域实现(CROS、JSONP)
    HttpRequestMessage扩展方法
    webapi基于单请求封装多请求的设计【转】
    webapi中获取HttpContext
    webapi序列化控制
    webapi简介及参数绑定
  • 原文地址:https://www.cnblogs.com/leo-tail-x/p/10067562.html
Copyright © 2011-2022 走看看