zoukankan      html  css  js  c++  java
  • django ----CBV中加装饰器

    CBV中加装饰器

    from django import views
    from django.utils.decorators import method_decorator
    
    def login_auth(func):
        def inner(request,*args,**kwargs):
            next_url=request.get_full_path()
            if request.COOKIES.get('is_login'):
                return func(request,*args,**kwargs)
            else:
                return redirect('cookie_login/?next=%s'%next_url)
        return inner

    # @method_decorator(login_auth,name
    ='get') # @method_decorator(login_auth,name='post') class UserList(views.View): # @method_decorator(login_auth) def dispatch(self, request, *args, **kwargs): obj=super().dispatch(request, *args, **kwargs) return obj @method_decorator(login_auth) def get(self,request): return HttpResponse('我是用户列表') def post(self,request): return HttpResponse('我是用户列表')
  • 相关阅读:
    第1章 数据结构绪论
    收集的名言警句
    Asp.net MVC知识积累
    我的书单
    ASP.NET Web API
    贱人语录
    正则表达式入门
    Lucene 3.0
    Solr之java操作
    Elasticsearch
  • 原文地址:https://www.cnblogs.com/di2wu/p/10062017.html
Copyright © 2011-2022 走看看