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()) # 路径信息 + 参数 
  • 相关阅读:
    一句话概括下spring框架及spring cloud框架主要组件
    服务注册与发现
    微服务API Gateway
    微服务分布式事务的一些思考
    微服务框架的存储架构
    轻量级微服务框架的通信架构
    基于Docker的负载均衡和服务发现
    测试一下标签
    让360安全浏览器默认使用谷歌内核
    schema中字段类型的定义
  • 原文地址:https://www.cnblogs.com/leo-tail-x/p/10067562.html
Copyright © 2011-2022 走看看