• django类视图的装饰器验证


    django类视图的装饰器验证


    • django类视图的get和post方法是由View内部调用dispatch方法来分发,最后调用as_view来完成一个视图的流程。
    • 函数视图可以直接使用对应的装饰器
    • 类视图可以用MixIn的方法来对类视图的dispatch或as_view方法对一个的封装
    • django提供了一个method_decorator的装饰器可以直接对类视图的处理方法进行装饰
    • from django.utils.decorators import method_decorator
      from django.contrib.auth.decorators import login_required
      from django.views import View
      from django.http import HttpResponse
      
      class TestView(View):
      
          @method_decorator(login_required)
          def get(self, request):
              return HttpResponse('hello world')
  • 相关阅读:
    Design Pattern Explained
    StringBuilder or StringBuffer
    Algorithms
    Difference between pages and blocks
    Date Time Calendar
    Math if fun
    Sublime Text
    Java Regex
    Learning C
    跨域通信/跨域上传浅析
  • 原文地址:https://www.cnblogs.com/ivy-blogs/p/11446423.html
Copyright © 2020-2023  润新知