首页 > 其他 > 详细

django中视图函数中装饰器

时间:2019-11-10 17:47:41      阅读:90      评论:0      收藏:0      [点我收藏+]

方法一

给指定方法加

from django.utils.decorators import method_decorator

class xx(View):
    @method_decorator(装饰器方法)
    def post(self, request):
                    ...

方法二

给dispatch加

@method_decorator(装饰器方法)
def dispatch(self, request, *args, **kwargs):
    ...

方法三

给类加

from django.utils.decorators import method_decorator
@method_decorator(装饰器方法, name="get")
@method_decorator(装饰器方法, name="post")
class xxxx(View):
    ... 

django中视图函数中装饰器

原文:https://www.cnblogs.com/pythonywy/p/11830935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!